Hi,
I have a form with a set of fields. All these fields belong to a table
called Textmaze. One of the form fields is a list box. This list box
gets it''s values from an existing table called Scenario in the
database. On submission of the form, it should create a record in a
table. Connection between these two tables looks like this:
class Textmaze < ActiveRecord::Base
belongs_to :starting_scenario,
:class_name => "Scenario",
:foreign_key => "starting_scenario"
---
end
My form code looks like this:
---
<select id="textmaze_starting_scenario"
name="textmaze[starting_scenario]">
<% @scenarios.each do |scenario| %>
<option value="<%= scenario %>">
<%= scenario.title %>
</option>
<% end %>
</select>
----
When I submit the form I get an error saying "Scenario expected, got
String"
Instead of <option value="<%= scenario %>"> I tried
supplying the id
of the Scenario record but even that doesn''t seem to work. What could
be wrong?
How can I get reference to another table''s record into my table?
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---
Hi,
I think you better use the built in select_option method from Ruby On
Rails. If you would have in your text_maze_controller.rb something like
this:
def ''edit''
@textmaze = Textmaze.find(params[:id])
@scenarios = Scenario.find(:all)
end
then you can use in your _form.rhtml view of your Textmaze something
like this:
<%=
collection_select("textmaze","starting_scenario",@scenarios,"id","title")
%>
It helps to keep the view clean. This answer comes from a ROR user for
four evenings.
Best regards,
Mark Noten
--
Posted via http://www.ruby-forum.com/.
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---
>From your description, it seems the problem is in the form actionmethod inside your controller. By the way, yes, you should code the option value as <option value="<%= scenario.id %>">. This will provide the key for doing a find on Scenario. The error is saying you supplied a string, rather an instance of Scenario, probably as a parameter to something. I would check your code that deals with Scenario. If you get stuck post the code up here. -Paul --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---