I have the following models:
Product: name, shop_id (foreign key)
Shop: name
The associations are:
Product: belongs_to :shop
Shop: has_many :products
In the form that creates a new Product I have:
<%= f.label(:shop, "Shop:") %>
<%= f.select(...) %>
This is a select box with all existing shops. The last option in this
select box is "Create New Shop". When user clicks this option,
Javascript shows an extra field:
<div id="new_shop_wrapper">
<label for="new_shop">New shop:</label>
<input id="new_shop" name="new_shop"
type="text" />
</div>
(This "div" is hidden by default with "display: none".)
How should I add this "div" in the Rails form creation ?
I tried:
<%= f.label(:new_shop, "New Shop:") %>
<%= f.text_field(:new_shop) %>
but it doesn''t work because "new_shop" is not
Product''s field.
I thought to use:
<%= text_field(<object>, :new_shop) %>
but I don''t know what <object> to use.
Please advise.
--
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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.
moroshko wrote in post #968250:> I have the following models: > > Product: name, shop_id (foreign key) > Shop: name > > The associations are: > > Product: belongs_to :shop > Shop: has_many :products > > In the form that creates a new Product I have: > > <%= f.label(:shop, "Shop:") %> > <%= f.select(...) %> > > This is a select box with all existing shops. The last option in this > select box is "Create New Shop". When user clicks this option, > Javascript shows an extra field: > > <div id="new_shop_wrapper"> > <label for="new_shop">New shop:</label> > <input id="new_shop" name="new_shop" type="text" /> > </div> > > (This "div" is hidden by default with "display: none".) > > How should I add this "div" in the Rails form creation ?Just put it in as HTML. There''s nothing magical here. Best, -- Marnen Laibow-Koser http://www.marnen.org marnen-sbuyVjPbboAdnm+yROfE0A@public.gmane.org Sent from my iPhone -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org 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.