Hello. I have a very simple problem but cannot find a nice solution. I have a lookup code in ruby (for example, Students that live in a State):
# State lookup (id, name)
class State < ActiveRecord::Base
has_many :students
end
# Class that belogs to a state
class Student< ActiveRecord::Base
belongs_to :state
end
and in the view/students/new.html.erb view, I display the states as a drop down:
<p>
<%= f.label :state %><br />
<%= f.collection_select :state, State.find(:all),
:id, :name, :prompt => "Select a State" %>
</p>
so far, so good, but when I hit save I got an error:
State(#37872860) expected, got String(#21001240)
what seems reasonable, as I'm sending a string instead of a State object to the Student.create method.
Which is the best way of handling this in RoR? I'm getting the State object in the controller by hand and replacing it in the parameters hash, but I think should be a better way.
Thanks very much. Fernando