FormBuilder in rjs

I have a page, which renders a partial that contains a ‘State’ drop
down list. Upon change, it re-renders the ‘City’ drop down, re-
populating it based on selected state_id:

Page: /customer/new.rhtml

<% form_for :customer, :url => customers_path do |f| %>

State: <%= f.collection_select :state_id, State.find(:all), ‘id’,
‘description’ %>
<%= observe_field :customer_state_id, :url => search_cities_url, :with
=> ‘search[state_id]’ %>

<.div id=‘state_div’><%= render :partial => ‘city/list’, :object =>
[], :locals => { :f => f } %>

<% end %>

class CustomerController…
def create
@customer = Customer.create params[:customer] # => { :state_id
=> X, :city_id => Y }

end
end

Partial: /city/_list.rhtml

City: <%= f.collection_select :city_id, list, ‘id’, ‘name’ %>

class CityController…
def search
@cities = City.find :all, :conditions => params[:search] # =>
{ :state_id => X }
end

RJS: /city/search.rjs

page.replace_html ‘state_div’, :partial => ‘list’, :object =>
@cities, :locals => { :f => ??? }

My problem is that when rendering my partial ‘city/list’ from
new.rhtml, I have access to my FormBuilder f and therefore can DRY up
my params hash key ‘customer’ for all form input elements I use in my
partial, which is great. However, when I render my partial from an
rjs, I no longer have access to the FormBuilder f. I don’t want to
hard-code the controller#params key ‘search’ inside my partial either
because I can have other rhtml pages that uses the same ‘city/list’
partial but want to render it inside a different form_for key
than :customer.

So here is my question: for my partial ‘city/_list.rhtml’, how can I
customize its controller#params POST key (eg. customer[:city_id]) such
that I can have multiple render entry points into the partial but not
all has the good-ole FormBuilder?

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs