Neil Middleton
Neil Middleton

Reputation: 22240

Accessing item attributes in a Rails form

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?

Upvotes: 0

Views: 202

Answers (2)

Simone Carletti
Simone Carletti

Reputation: 176552

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

Upvotes: 3

Zepplock
Zepplock

Reputation: 29175

f.property.active

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

Upvotes: 0

Related Questions