# FormBuilder in rjs

**URL:** <https://www.ruby-forum.com/t/formbuilder-in-rjs/112538>\
**Category:** Rails\
**Created:** [August 20, 2007, 7:02pm UTC](https://www.ruby-forum.com/t/formbuilder-in-rjs/112538 "2007-08-20T19:02:49Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![developer810](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/53a042/32.png) [@developer810](https://www.ruby-forum.com/u/developer810)\
**Post date:** [August 20, 2007, 7:02pm UTC](https://www.ruby-forum.com/t/formbuilder-in-rjs/112538/1 "2007-08-20T19:02:49Z")

</div>

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?
