# Help with action for update

**URL:** <https://www.ruby-forum.com/t/help-with-action-for-update/68207>\
**Category:** Rails\
**Created:** [September 10, 2006, 2:06pm UTC](https://www.ruby-forum.com/t/help-with-action-for-update/68207 "2006-09-10T14:06:40Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![zanoni](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/e99b99/32.png) [@zanoni](https://www.ruby-forum.com/u/zanoni)\
**Post date:** [September 10, 2006, 2:06pm UTC](https://www.ruby-forum.com/t/help-with-action-for-update/68207/1 "2006-09-10T14:06:40Z")

</div>

I’m working on setting up a form where one element gets updated  
depending on what value was checked in another element. Sadly though  
I’m not sure exactly what to do with my controller action and if i’ll  
need to depend on form\_tag\_remote. I do want the element updated  
before submit so probably not needing the form\_tag call.

So far my view looks like this:

\<%=  
@pays = Pay.find(:all, :order =\> “id”).map {|p| [p.name, p.id] }  
select(:pay, :name, @pays) %\>

\<%=  
 @wages = Wage.find(:all, :order =\> “id”).map {|p| [p.name, p.id] }  
select(:wage, :name, @wages, {},{:disabled =\> true}) %\>

\<%= observe\_field(“pay[id]”,  
:frequency =\> 0.25,  
:update =\> “wagespec”,  
:url =\> {:action =\> :get\_wages},  
:with =\> “‘pay\_id=’+value”)  
%\>

So I need to create an action called get\_wages that will enable and  
update @wages. Are there special calls to accomplish this ?

TIA  
Stuart

---

<div class="post-metadata">

**Author:** ![zanoni](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/e99b99/32.png) [@zanoni](https://www.ruby-forum.com/u/zanoni)\
**Post date:** [September 10, 2006, 6:11pm UTC](https://www.ruby-forum.com/t/help-with-action-for-update/68207/2 "2006-09-10T18:11:00Z")

</div>

Updating this thread. First is 3 days on the same problem unusual or  
an indication not to give up my day job ?

Okay, I’m still trying to do a dynamic drop down based on user choice  
in first select.  
I came across this post -  
[http://www.ruby-forum.com/topic/61521](http://www.ruby-forum.com/topic/61521)  
and translating to my setup , so far it’s not working , then again no  
errors in log or debug.

First, I have two tables/model ‘pay’ with an id and name, and wage  
with an id, pay\_id, and name.

When user choose pay, I want to take the id of the pay selection and  
update, or load partial from wage select.

Using the example above I created the following files:

#view

Pay Type  
 \<%= options\_from\_collection\_for\_select( Pay.find\_all, "id", "name") %\>

Wage specifics  
 

\<%= observe\_field(“pay[id]”,  
:frequency =\> 0.0,  
:update =\> “wage\_list”,  
:url =\> {:action =\> :fill\_wages},  
:with =\> “‘wage[pay\_id]=’+value”) %\>

#controller method  
def fill\_wages  
@lookups = Lookup.find\_all\_by\_list\_prompt(@params[:wage], :order  
=\> ‘pay\_id’)  
render :partial =\> ‘wagespecs’  
end

I also created \_wagespecs though Im not entirely sure what goes in  
there since the example above didn’t show it .

Anyone give me some help on this ?  
Stuart

---

<div class="post-metadata">

**Author:** ![zanoni](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/e99b99/32.png) [@zanoni](https://www.ruby-forum.com/u/zanoni)\
**Post date:** [September 10, 2006, 7:47pm UTC](https://www.ruby-forum.com/t/help-with-action-for-update/68207/3 "2006-09-10T19:47:13Z")

</div>

Hello “Dark” (strange first name, but, hey, thats what makes the world  
go round\* 😉  
I do something similiar to what your asking, except I use Agent’s  
and their currency. The quirk comes that if an agent only has one  
currency, then it shouldn’t even offer a select box, but rather default  
to the single currency. Here is how I do it, you can take from it what  
you want (or not, your choice ;);

```
views/booking/new.html

<p/>
    <% agent_change_ajax = remote_function(:update => :currencyList,
                :url => { :controller => 'agent', :action =>

```

:list\_currency\_ajax\_search },  
:with =\> “‘agentid=’+value”)  
%\>  
The Agent for this Booking is :  
  
\<%= select(‘booking’, ‘agent’, Agent.default\_quickbook\_options,  
{ :selected =\> 2828 }, { :onchange =\> agent\_change\_ajax }) %\>

```
<p/>
<div id="currencyList">
    <label for="booking_currency">Which Currency should this Booking

```

be made in :   
  
\<%= select(‘booking’, ‘currency’, Currency.currency\_options, {  
:selected =\> 2 }) %\>

```
controllers/agent_controller.rb

def list_currency_ajax_search
    myAgent = Agent.find(params['agentid'])
    @currencies = myAgent.currency # obtained by the model Agent

```

having a relation to currencies  
render(:layout=\>false,:partial =\> ‘list\_currency\_ajax\_search’)  
end

```
views/agent/_list_currency_ajax_search.rhtml

```

\<% if @currencies.size == 1 %\>  
  
Agent only accepts \<%=  
@currencies.first.iso\_code %\>   
\<% else %\>  
Which Currency should this Booking be  
made in :   
  
Please Select One  
\<% for currency in @currencies do -%\>  
\<%= currency.iso\_code  
%\>  
\<% end -%\>  
  
\<% end %\>

```
Hopefully, you should get an idea of what to do from this. I would

```

say having an ‘onchange’ is better than having a constantly polling  
observer, but, I am not 1000% sure that observe\_field does what I think  
it does. Eh. ymmv '🙂

```
Regards
Stef

```

(\* apparently so does ; love, money, sex and rock n roll)
