Sunday, October 17, 2010

[Rails] How to Pass a Selected Option Value of select_tag from One Partial to Another

Hi,

I'm running Rails 2.3.5 & Ruby 1.8.7 on Windows XP.

I have two partials:
1. File app\views\warehousing\_index.html.erb has
.....
<%= select_tag(:filter_by_category, "<option>-Select a category-
</option>" +

options_from_collection_for_select(Categories.find(:all, :order =>
'name'), :name, :name)) %>
.....
<%= render :partial => 'warehousing/entry', :locals =>
{:filter_by_category => "Hello World"} %>
.....
2. File app\views\warehousing\_entry.html.erb has
.....
<div>Selected category is <%= filter_by_category %></div>
.....

On the displayed page, it shows:

Selected category is Hello World

That means the string "Hello World" in variable filter_by_category is
indeed passed from one partial to the other. For my project, I want
to pass the selected option value from the select_tag to partial
_entry.html.erb, i.e. in file _entry.html.erb, for line
<%= render :partial => 'warehousing/entry', :locals =>
{:filter_by_category => ???} %>
what should I put in for "???".

Thanks for any help that you could offer.
Hoca

--
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