# Problem with rails and AJAX

**URL:** <https://www.ruby-forum.com/t/problem-with-rails-and-ajax/172186>\
**Category:** Rails\
**Created:** [July 16, 2009, 1:25pm UTC](https://www.ruby-forum.com/t/problem-with-rails-and-ajax/172186 "2009-07-16T13:25:58Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![shakor](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/bcef8e/32.png) [@shakor](https://www.ruby-forum.com/u/shakor)\
**Post date:** [July 16, 2009, 1:25pm UTC](https://www.ruby-forum.com/t/problem-with-rails-and-ajax/172186/1 "2009-07-16T13:25:58Z")

</div>

Hi,

I have a very simple page with a drop down select list and I want that a  
portion of this page gets updated each time a new selection is done on  
the select list.

This is my page with the select list (edit view\_sites.html.erb):

\<% form\_for :site, :url =\> { :action =\> :edit\_site } do |form| %\>

\<%= form.label(:name, "Location Code:") %\> \<%= collection\_select(:VMetaLocationPopulated, :location\_code, loc\_entities, :location\_code, :location\_code, options ={:prompt =\> "-Select a Location Code"}) %\> \<%= observe\_field 'VMetaLocationPopulated\_location\_code', :url =\> {:action =\> :update\_edit\_view, :form\_authenticity\_token =\> form\_authenticity\_token }, :update =\> :dynamic\_content, :with =\> '"locid="+element.value', :locals =\> { :form =\> form }, :loading =\> "Element.show('indicator')", :complete =\> "Element.hide('indicator')" %\>

\<% end %\>

And the action method (update\_edit\_view) in the controller class is  
empty since I just want it to forward to the dynamic\_content page. So  
this is that page (update\_edit\_view.erb):

\<%if(params[:locid] != nil)%\>  
\<%= form.label(:name, “Location Name:”) %\>  
\<%= form.text\_field(:locid, :size =\> 40) %\>  
\<%else%\>

\<%end%\>

So this should work but the error I get is:

ArgumentError in Main#update\_edit\_view  
Showing app/views/main/update\_edit\_view.erb where line #3 raised:

wrong number of arguments (0 for 1)  
Extracted source (around line #3):

1:   
2: \<%if(params[:locid] != nil)%\>  
3: \<%= form.label(:name, “Location Name:”) %\>  
4: \<%= form.text\_field(:locid, :size =\> 40) %\>  
5: \<%else%\>

Why is it complaining about the form.label method? It works fine if I  
copy paste it on the main page but in this partial one it does not work.  
I assume it has got to do with not being able to find the ‘form’  
variable but I passed it on by using the line: :locals =\> { :form =\>  
form }

So why doesn’t it work?

---

<div class="post-metadata">

**Author:** ![shakor](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/bcef8e/32.png) [@shakor](https://www.ruby-forum.com/u/shakor)\
**Post date:** [July 17, 2009, 2:38pm UTC](https://www.ruby-forum.com/t/problem-with-rails-and-ajax/172186/2 "2009-07-17T14:38:01Z")

</div>

Noone knows how to pass a form reference to a partial page when using  
observe\_field?
