firstruby

Master ruby with us

Posts Tagged ‘RoR’

Restrict rake routes listing to particular Controller in Ruby on Rails

Posted by firstruby on May 9, 2010

We can restrict the routes listing to particular CONTROLLER by passing CONTROLLER variable as,

rake routes CONTROLLER=profiles

Above command will display routes of profiles controller.

Posted in Useful Links | Tagged: , , , | Leave a Comment »

AJAX pagination in Ruby on Rails

Posted by firstruby on November 29, 2009

For users list, I wanted to have AJAX pagination.

For Ruby on Rails version 2.3.x,

1) Install will_paginate gem “config.gem “will_paginate”" or include will_paginate plugin in vendor/plugins.

2) Create helper file at /app/helpers/remote_link_renderer.rb with following content,
remote_link_renderer.rb
Here I’m attaching remote_link_renderer.rb.pdf file , copy contents from remote_link_renderer.rb.pdf and create file remote_link_renderer.rb

3) In controller action, write as following,

if request.xhr?
render :update do |page|
page.replace_html "users_list", :partial => "users", : object => @users
end
end

4) On “_users_list.html.erb” view page, write as,

= will_paginate @users, :renderer => 'RemoteLinkRenderer'

Posted in Useful Links | Tagged: , , , , | Leave a Comment »

Configuration for Oracle with Ruby On Rails on Windows

Posted by firstruby on June 26, 2009

To configure the Oracle with Ruby on Rails (RoR) applications, we need to do following setting,

Download Oracle 10g from http://download.oracle.com/otn/nt/oracle10g/xe/10201/OracleXEUniv.exe (to download Oracle setup, you need to create an account)

Install following gems,

gem install activerecord-oracle_enhanced-adapter
gem install ruby-oci8

Then modify the /config/database.yml as following for the current environment,


adapter: oracle_enhanced
host: localhost
username: db_user_name
password: db_password
encoding: utf8

Posted in firstruby, Useful Links | Tagged: , , | Leave a Comment »

Git – create git branch

Posted by firstruby on November 2, 2008

Create new branch “demo” as,

1) git branch demo

This will create local branch “demo”

2) git checkout demo

This will switched to that branch

3) make some changes in that code, then,

git add <files>
git commit -m "<your message>"

4) git push origin demo

This will create new remote branch “demo” on github.

5) If you want someone to checkout the code from “demo” branch, then do following,

git clone <git-path>

then,

git checkout --track -b demo origin/demo

Now, you are in “demo” branch.

Posted in Blogroll, firstruby, Useful Links | Tagged: , , | 1 Comment »

RESTful architecture

Posted by firstruby on May 29, 2008

RESTful interface means clean URLs, less code, CRUD interface.

CRUD means Create-READ-UPDATE-DESTROY.

You might heard about HTTP verbs, GET, POST. In REST, they add 2 new verbs, i.e, PUT, DELETE.

There are 7 default actions, those are – index, show, new, create, edit, update, destroy

GET is used when you retrieve data from database. POST is used when you create new record in database. PUT is used when you are updating any existing record in database, and DELETE is used when you are destroying any record in database. Following table may clear the concept.

Action VERB

index                        GET

show                        GET

new                          GET

create                       POST

edit                          GET

update                      PUT

destroy                    DELETE

Posted in firstruby, Forum, Useful Links | Tagged: , , | 1 Comment »

DateTime formatting in RubyonRails

Posted by firstruby on May 29, 2008

To display datetimes in different formats in Ruby On Rails application,

following may help,

Format meaning:
%a – The abbreviated weekday name (“Sun”)
%A – The full weekday name (“Sunday”)
%b – The abbreviated month name (“Jan”)
%B – The full month name (“January”)
%c – The preferred local date and time representation
%d – Day of the month (01..31)
%H – Hour of the day, 24-hour clock (00..23)
%I – Hour of the day, 12-hour clock (01..12)
%j – Day of the year (001..366)
%m – Month of the year (01..12)
%M – Minute of the hour (00..59)
%p – Meridian indicator (“AM” or “PM”)
%S – Second of the minute (00..60)
%U – Week number of the current year, starting with the first Sunday as the first day of the first week (00..53)
%W – Week number of the current year, starting with the first Monday as the first day of the first week (00..53)
%w – Day of the week (Sunday is 0, 0..6)
%x – Preferred representation for the date alone, no time
%X – Preferred representation for the time alone, no date
%y – Year without a century (00..99)
%Y – Year with century
%Z – Time zone name
%% – Literal “%” character

For example,

t = Time.now
t.strftime(“Printed on %m/%d/%Y”) #=> “Printed on 04/09/2003″
t.strftime(“at %I:%M%p”) #=> “at 08:56AM”

Posted in firstruby, Forum, Useful Links | Tagged: , , , | 2 Comments »

iCal ( iCalendar ) Publishing to *.ics file through RubyOnRails

Posted by firstruby on December 10, 2007

To publish iCal through Rails, install iCalendar gem

gem install icalendar

then in Controller, code to export event ( export to *.ics file ) should look like,

require 'icalendar'
class EventController < ApplicationController
def export_events
@event = Event.find(params[:id])
@calendar = Icalendar::Calendar.new
event = Icalendar::Event.new
event.start = @event.dt_time.strftime("%Y%m%dT%H%M%S")
event.end = @event.dt_time.strftime("%Y%m%dT%H%M%S")
event.summary = @event.summary
event.description = @event.description
event.location = @event.location
@calendar.add event
@calendar.publish
headers['Content-Type'] = "text/calendar; charset=UTF-8"
render_without_layout :text => @calendar.to_ical
end
end

Posted in Useful Links | Tagged: , | 3 Comments »

 
Follow

Get every new post delivered to your Inbox.