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