Instant Variables in Ruby on Rails

Hello friend we often require instant variable which we need to call in our entire application for dynamic content .Here is solution for that , just declare this method in application.rb (controller), put in before_filter:settinginstantvars. This is done have fun with instant variable.
____________________________________________________________
def settinginstantvars()
@model = Model.find(:all);
@model.each do |c|
instance_variable_set(“@#{c.name}”,c.value)
end
end
____________________________________________________________

When you need them just do @name (name of field in your table).
Have fun.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s