Hoca
2010-Oct-18  01:34 UTC
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-/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.
Marnen Laibow-Koser
2010-Oct-18  15:45 UTC
Re: How to Pass a Selected Option Value of select_tag from One Partial to Another
Hoca wrote in post #955056:> Hi, > > I''m running Rails 2.3.5 & Ruby 1.8.7 on Windows XP.Why on earth are you doing Rails development on Windows? At least get a *nix VM.> > 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 "???".It''s not possible, because at the time the partial is rendered, the user has not yet had a chance to select anything -- that is, by the time the user sees the page in the browser, _entry has already been rendered and it is now too late to change it. Therefore, you''d need to use Ajax to send a request to the server which would re-render _entry when a new category is selected.> > Thanks for any help that you could offer. > HocaBest, -- Marnen Laibow-Koser http://www.marnen.org marnen-sbuyVjPbboAdnm+yROfE0A@public.gmane.org -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Hoca
2010-Oct-19  01:02 UTC
Re: How to Pass a Selected Option Value of select_tag from One Partial to Another
Hi Marnen, Thanks so much for your suggestion. I''ll try another approach then. 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-/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.