# help with action for update

**URL:** <https://discuss.rubyonrails.org/t/help-with-action-for-update/1387>\
**Category:** rubyonrails-talk\
**Created:** [September 10, 2006, 12:00pm UTC](https://discuss.rubyonrails.org/t/help-with-action-for-update/1387 "2006-09-10T12:00:01Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Dark\_Ambient](https://avatars.discourse-cdn.com/v4/letter/d/e9bcb4/32.png) [@Dark\_Ambient](https://discuss.rubyonrails.org/u/Dark_Ambient)\
**Post date:** [September 10, 2006, 12:00pm UTC](https://discuss.rubyonrails.org/t/help-with-action-for-update/1387/1 "2006-09-10T12:00:01Z")

</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) %\>

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

\<%= observe\_field("pay[id]", &nbsp;&nbsp;:frequency =\> 0.25, &nbsp;&nbsp;:update =\> "wagespec", &nbsp;&nbsp;:url =\> {:action =\> :get\_wages}, &nbsp;&nbsp;: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:** ![Dark\_Ambient](https://avatars.discourse-cdn.com/v4/letter/d/e9bcb4/32.png) [@Dark\_Ambient](https://discuss.rubyonrails.org/u/Dark_Ambient)\
**Post date:** [September 10, 2006, 4:02pm UTC](https://discuss.rubyonrails.org/t/help-with-action-for-update/1387/2 "2006-09-10T16:02:45Z")

</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 -

> **[Help With Dependent Drop-Down and @Params](https://www.ruby-forum.com/t/help-with-dependent-drop-down-and-params/57311)**
>
> Hello All: I am trying to create a select box that is filled with options based on the user’s selection in a related drop-down. I have had success with this before using the examples provided by the following two sources: One posted by Rory at...

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 \<p\>\<label for="pay"\>Pay Type\</label\>\<br/\> \<select id="pay[id] name="pay[id]"\> &nbsp;&nbsp;\<%= options\_from\_collection\_for\_select( &nbsp;&nbsp;&nbsp;Pay.find\_all, "id", "name") %\> \</select\>\</p\>

\<span id="wage\_list"\> \<label for="wage"\>Wage specifics\</label\>\<br/\> &nbsp;&nbsp;\<select id="wage[pay\_id]" name="wage[pay\_id]"\>\</select\> \</span\>

\<%= observe\_field("pay[id]", &nbsp;&nbsp;&nbsp;&nbsp;:frequency =\> 0.0, &nbsp;&nbsp;&nbsp;&nbsp;:update =\> "wage\_list", &nbsp;&nbsp;&nbsp;&nbsp;:url =\> {:action =\> :fill\_wages}, &nbsp;&nbsp;&nbsp;&nbsp;:with =\> "'wage[pay\_id]='+value") %\>

#controller method &nbsp;&nbsp;def fill\_wages &nbsp;&nbsp;&nbsp;&nbsp;@lookups = Lookup.find\_all\_by\_list\_prompt(@params[:wage], :order =\> 'pay\_id') &nbsp;&nbsp;&nbsp;&nbsp;render :partial =\> 'wagespecs' &nbsp;&nbsp;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:** ![Stef\_T](https://avatars.discourse-cdn.com/v4/letter/s/5e9695/32.png) [@Stef\_T](https://discuss.rubyonrails.org/u/Stef_T)\
**Post date:** [September 10, 2006, 5:43pm UTC](https://discuss.rubyonrails.org/t/help-with-action-for-update/1387/3 "2006-09-10T17:43:11Z")

</div>

Hello "Dark" (strange first name, but, hey, thats what makes the world go round\* 😉&nbsp;&nbsp;&nbsp;&nbsp;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 ;);

&nbsp;&nbsp;&nbsp;&nbsp;views/booking/new.html

&nbsp;&nbsp;&nbsp;&nbsp;\<p/\> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\<% agent\_change\_ajax = remote\_function(:update =\> :currencyList, &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:url =\> { :controller =\> 'agent', :action =\> :list\_currency\_ajax\_search }, &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:with =\> "'agentid='+value") &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;%\> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\<label for="booking\_agent"\>The Agent for this Booking is : \</label\> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\<%= select('booking', 'agent', Agent.default\_quickbook\_options, { :selected =\> 2828 }, { :onchange =\> agent\_change\_ajax }) %\>

&nbsp;&nbsp;&nbsp;&nbsp;\<p/\> &nbsp;&nbsp;&nbsp;&nbsp;\<div id="currencyList"\> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\<label for="booking\_currency"\>Which Currency should this Booking be made in : \</label\> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\<!-- setup the default currency for the first pass //--\> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\<%= select('booking', 'currency', Currency.currency\_options, { :selected =\> 2 }) %\> &nbsp;&nbsp;&nbsp;&nbsp;\</div\>

&nbsp;&nbsp;&nbsp;&nbsp;controllers/agent\_controller.rb

&nbsp;&nbsp;&nbsp;&nbsp;def list\_currency\_ajax\_search &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;myAgent = Agent.find(params['agentid']) &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;@currencies = myAgent.currency # obtained by the model Agent having a relation to currencies &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;render(:layout=\>false,:partial =\> 'list\_currency\_ajax\_search') &nbsp;&nbsp;&nbsp;&nbsp;end

&nbsp;&nbsp;&nbsp;&nbsp;views/agent/\_list\_currency\_ajax\_search.rhtml &nbsp;&nbsp;&nbsp; \<% if @currencies.size == 1 %\> &nbsp;&nbsp;&nbsp;&nbsp;\<input type="hidden" id="booking\_currency" name="booking[currency]" value="\<%= @currencies. first.currency\_id %\>" /\> &nbsp;&nbsp;&nbsp;&nbsp;\<label for="booking\_currency"\>Agent only accepts \<%= @currencies.first.iso\_code %\> \</label\> \<% else %\> &nbsp;&nbsp;&nbsp;&nbsp;\<label for="booking\_currency"\>Which Currency should this Booking be made in : \</label\> &nbsp;&nbsp;&nbsp;&nbsp;\<select id="booking\_currency" name="booking[currency]"\> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\<option value="" selected="selected"\>Please Select One\</option\> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\<% for currency in @currencies do -%\> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\<option value="\<%= currency.id %\>"\>\<%= currency.iso\_code %\>\</option\> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\<% end -%\> &nbsp;&nbsp;&nbsp;&nbsp;\</select\> \<% end %\>

&nbsp;&nbsp;&nbsp;&nbsp;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 '🙂

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

Dark Ambient wrote:
