Never been to DZone Snippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

About this user

Rajkumar S

« Newer Snippets
Older Snippets »
Showing 1-6 of 6 total  RSS 

Install DateBocks

Install engines plugin

./script/plugin source http://svn.rails-engines.org/plugins/
./script/plugin install engines


Install datebocks

./script/plugin source http://svn.toolbocks.com/plugins
./script/plugin install datebocks_engine

Select field from database with option selected

to post sess[callcenter_client_id]

select("sess", "callcenter_client_id", CallcenterClient.find_all.collect {|p| [ p.name, p.id ] }, { :selected => @sess.callcenter_client_id.to_i })


make sure that the :selected entry is an integer.

Render partial

<%= render(:partial         => "animal" ,
           :collection      => %w{ ant bee cat dog elk },
           :spacer_template => "spacer" )
%>

animal is the name of template and local variable holding each element of collection inside the partial. animal_counter holds the index of current element in the collection. spacer_template is rendered between each elements in the collection.

if clause

// description of your code here

((counter % 2) == 0) ? 'light' : 'dark' 

Create a date 4 weeks ago from the current date

// description of your code here

t = 4.weeks.ago

Assign a variable a value if it's nil

There is a nifty way to give a variable a value if it's nil

a[i] ||=0


This is useful when you want to assign a value to an array and it's not yet initialized.
« Newer Snippets
Older Snippets »
Showing 1-6 of 6 total  RSS