views:

53

answers:

3

If I am inside a form block in Rails, e.g

form_for @widget do |f|
end

and am thus able to do things such as f.text_field :attribute etc, how can I also find out what the value of different attributes are in order to carry out some display logic?

For instance, something like

form_for @widget do |f|
  f.text_field :some_property
  f.checkbox :active if ????.active
end

How can I access the properties?

A: 

f.object.active etc

Neil Middleton
A: 

f.property.active

where property is any defined method or property of your @widget or the parent of Widget (ActiveRecord usually)

Zepplock
+3  A: 
form_for @widget do |f|
  f.text_field :some_property
  f.checkbox :active if @widget.active?
end
Simone Carletti