Hi,
I''ve been working with rails for a couple of months now and
I''m
beginning to understand how things work but this has got me baffled.
I want to return the user.id from a selection of a list of user
names. I followed the example from AWD w/ Rails (page 487) on how to
use collection_select but the controller barfs because it wants a user
and the id is coming back as a string.
Here are the code snippets:
FROM THE RHTML FORM:
<% form_for :master, :url => { :action => :create, :id => @master}
do |
form| %>
Owner: <%= @users = User.find(:all, :order => "last_name")
form.collection_select(:owner, @users, :id, :full_name) %>
<br/><br/>
IN THE CONTROLLER:
def create
begin
@requirement = Requirement.new(params[:requirement]) <<<<FAILS
HERE BECAUSE OWNER RECEIVES a STRING INSTEAD OF A USER OBJECT
IN THE MODELS:
master.rb
belongs_to :owner, :class_name => ''User'',
:foreign_key =>
''owner''
user.rb
has_many :owned_masters, :class_name =>
''Master'', :foreign_key => ''owner''
I suspect that my form is not quite right but I have already tried
several different combinations, all with the same result that I gave
here. The selection list in the html is being populated correctly
with the names I want but when I return the id the controller says I''m
returning a string and it wants a user object. How do I reconcile
this?
Thanks for any suggestions,
lac
--~--~---------~--~----~------------~-------~--~----~
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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---