Hello, How can I use a form variable in a partial rendered from within a page.replace_html rjs call? Here''s the problem: I''m trying to render a partial with form fields using rjs. In the erb template: <% form_for :availability, @availability, :url => { :action => "post_listing" } do |f| %> <%= f.select @availability, availabilities, :id => "availability_type" %> <%= observe_field(:availability_, :frequency => 0.5, :update => :availability, :url => { :controller => ''listing'', :action => :change_availability_type}) %> <% end %> In the controller action: def change_availability_type render :update do |page| page.replace_html "availability", :partial => "dry_lease" end end In the partial _dry_lease.rhtml: <%= f.text_field :dry_lease_min_months %></p> The problem is that the variable f in the partial above (i.e., f.text_field) is not set (it''s nil). In this part of the appllication, I need to dynamically render different partials with form elements depending on the option selected by the user. When not using rjs, you could just pass the form variable to the partial using :locals => { }. But in rjs, the call to page.replace_html takes place in the controller, it''s not clear how the form variable f could be set in the partial. Thanks. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
you can pass a parameter with the :with option http://wiki.rubyonrails.org/rails/pages/observe_field+-+Passing+Parameters On Jun 14, 10:25 am, athem <allan.m.mil...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Hello, > > How can I use a form variable in a partial rendered from within a > page.replace_html rjs call? Here''s the problem: > > I''m trying to render a partial with form fields using rjs. > > In the erb template: > > <% form_for :availability, @availability, :url => { :action => > "post_listing" } do |f| %> > > <%= f.select @availability, availabilities, :id => "availability_type" > %> > > <%= observe_field(:availability_, > :frequency => 0.5, > :update => :availability, > :url => { :controller => > ''listing'', :action => :change_availability_type}) %> > > <% end %> > > In the controller action: > > def change_availability_type > render :update do |page| > page.replace_html "availability", :partial => "dry_lease" > end > end > > In the partial _dry_lease.rhtml: > > <%= f.text_field :dry_lease_min_months %></p> > > The problem is that the variable f in the partial above (i.e., > f.text_field) is not set (it''s nil). > > In this part of the appllication, I need to dynamically render > different partials with form elements depending on the option selected > by the user. > > When not using rjs, you could just pass the form variable to the > partial using :locals => { }. But in rjs, the call to > page.replace_html takes place in the controller, it''s not clear how > the form variable f could be set in the partial. > > Thanks.--~--~---------~--~----~------------~-------~--~----~ 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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On 14 Jun 2008, at 18:25, athem wrote:> > def change_availability_type > render :update do |page| > page.replace_html "availability", :partial => "dry_lease" > end > end > > In the partial _dry_lease.rhtml: > > <%= f.text_field :dry_lease_min_months %></p> >You''re going to need to create the form builder yourself. obviously you don''t want form_for since that would create form tags etc..., you just want the bit of form_for that knows how to name form parameters and so on, that bit is fields_for. Fred> The problem is that the variable f in the partial above (i.e., > f.text_field) is not set (it''s nil). > > In this part of the appllication, I need to dynamically render > different partials with form elements depending on the option selected > by the user. > > When not using rjs, you could just pass the form variable to the > partial using :locals => { }. But in rjs, the call to > page.replace_html takes place in the controller, it''s not clear how > the form variable f could be set in the partial. > > Thanks. > >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
On Jun 15, 9:42 am, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On 14 Jun 2008, at 18:25, athem wrote: > > > > > def change_availability_type > > render :update do |page| > > page.replace_html "availability", :partial => "dry_lease" > > end > > end > > > In the partial _dry_lease.rhtml: > > > <%= f.text_field :dry_lease_min_months %></p> > > You''re going to need to create the form builder yourself. obviously > you don''t want form_for since that would create form tags etc..., you > just want the bit of form_for that knows how to name form parameters > and so on, that bit is fields_for. > > Fred > > > The problem is that the variable f in the partial above (i.e., > > f.text_field) is not set (it''s nil). > > > In this part of the appllication, I need to dynamically render > > different partials with form elements depending on the option selected > > by the user. > > > When not using rjs, you could just pass the form variable to the > > partial using :locals => { }. But in rjs, the call to > > page.replace_html takes place in the controller, it''s not clear how > > the form variable f could be set in the partial. > > > Thanks.Based on Fred''s suggestion, the solution is to (1) continue to use form_for to create the form, but (2) enclose the fields in each of the partials using fields_for. Each of the partials is then self- contained and can be dropped into the form using RJS page.replace_html. Thanks. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---