Thursday, October 7, 2010

[Rails] How to access virtual attributes in the model

I've got an artist form. In this form I've got attributes that do not
exist in the model that the form belongs to. However, I would like to
submit these values for later processing.

My virtual attributes in the form are:

<%= f.label :foobar %>
<%= f.text_field :foobar %>

In the artist model, I created a getter:

def foobar
end

When the form is submitted, I am able to access the value of the
virtual attribute by doing, for example: puts params[:artist][:foobar]
in the controller (in the create method):

def create
@artist = Artist.new(params[:artist])

# return the value of the virtual attribute
puts params[:artist][:foobar]
...
end

I would like to do the same thing in the model? How can foobar be
accessed in the model? Or is this not possible?

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate