# Passing Multiple Parameters from observe\_field

**URL:** <https://www.ruby-forum.com/t/passing-multiple-parameters-from-observe-field/112949>\
**Category:** Rails\
**Created:** [August 24, 2007, 9:38pm UTC](https://www.ruby-forum.com/t/passing-multiple-parameters-from-observe-field/112949 "2007-08-24T21:38:00Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Philip\_N](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/c5a1d2/32.png) [@Philip\_N](https://www.ruby-forum.com/u/Philip_N)\
**Post date:** [August 24, 2007, 9:38pm UTC](https://www.ruby-forum.com/t/passing-multiple-parameters-from-observe-field/112949/1 "2007-08-24T21:38:00Z")

</div>

I need to pass through two parameters to a controller method from an  
observe\_field : the value of the field and another local variable.

I can get it working for either of the two, but not for both.

This is what I’m got in the form partial I’m trying to write  
(purchaser\_country\_id is coming in as a :local) -

Zip Code  
 \<%= text\_field 'order', 'purchaser\_zipcode', :size =\> 20 %\>

\<% if Zipcode.exists?([“state\_id in (select id from dbfox001.states  
where  
country\_id = ?)”, purchaser\_country\_id]) %\>

\<%= ‘Zipcodes exist for ’ + purchaser\_country\_id.to\_s %\>  
\<%=  
observe\_field :order\_purchaser\_zipcode,  
:update =\> ‘purchaser\_loc2’,  
:url =\> { :controller =\> ‘order’, :action =\>  
‘findzip’ },  
:with  
=\>  
"‘purchaser\_country\_id=’+purchaser\_country\_id.to\_s+’&purchaser\_zipcode=’+encodeURIComponent(value)"  
%\>  
\<% else %\>  
  
\<%= 'No zipcodes for ’ + purchaser\_country\_id.to\_s %\>  
\<% end %\>

 \<%= render :partial =\> "purchaser\_location2", :locals =\> {:purchaser\_country\_id =\> purchaser\_country\_id, :purchaser\_zipcode =\> ''} %\>

```
  <p><label for="order_purchaser_city">City</label><br/>
  <%= text_field 'order', 'purchaser_city', :size => 50 %></p>

```

If one of the fields is a literal it works : for example -

:with  
=\>  
“‘purchaser\_zipcode=’+encodeURIComponent(value)+’&purchaser\_country\_id=’+‘101’”

Any help appreciated.

Thanks

Phil

---

<div class="post-metadata">

**Author:** ![Philip\_N](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/c5a1d2/32.png) [@Philip\_N](https://www.ruby-forum.com/u/Philip_N)\
**Post date:** [August 25, 2007, 8:22pm UTC](https://www.ruby-forum.com/t/passing-multiple-parameters-from-observe-field/112949/2 "2007-08-25T20:22:02Z")

</div>

I had the same problem up until a couple of minutes ago. Try this:

with =\>  
“‘purchaser\_country\_id=#{purchaser\_country\_id}&purchaser\_zipcode=’+encodeURIComponent(value)”

Sean

---

<div class="post-metadata">

**Author:** ![Philip\_N](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/c5a1d2/32.png) [@Philip\_N](https://www.ruby-forum.com/u/Philip_N)\
**Post date:** [August 25, 2007, 8:43pm UTC](https://www.ruby-forum.com/t/passing-multiple-parameters-from-observe-field/112949/3 "2007-08-25T20:43:05Z")

</div>

Sean,

Thanks for that : I managed to resolve this last night (with the same  
solution) after some help on the RoR chat forum.

Thanks very much.

Phil
