开发者

How to update two f.select from 2 different tables on ruby on rails

I just started working on a Ruby On Rails project and i got to the point where i need to see the contacts of a company.

They should appear once the company is selected..

<p>
    <%= f.label :empresa_id %><br />
    <%= f.select(:empresa_id, @empresa.map {|e| [e.nombre, e.id]} )%>
</p>

<%= observe_field  :empresa_id, :url=>{:action => "get_contactos", 
     :controller=> :contactos, :updatewith =>:empresa_id} %>

But nothing happens, i don't see even a error on the script/server.

Can someone point me in the right direction?

http://nealenssle.com/blog/2007/04/12/how-to-dynamically-update-form-elements-in-rails-using-ajax/

I see on the link that a guy did the exact same thing i need but did no开发者_如何学Ct post any info.

Cheers.


Kinda got this working.. here's my update..

This is the form were my select boxes are placed:

"> "contacto_id", :with => "empresa_id", :url => { :controller => "contactos", :action => "get_contactos" } %>

The function get_contactos on the contactos controller :

def get_contactos @contacto = Contacto.find_all_by_empresa_id(params[:empresa_id]) render :layout => false end

And the view get_contactos.rhtml (contactos):

">%>

I just need to bind the form to the correct fields and the job will be finished.

I couldn't get this to work by observing the field :empresa_id but "empresa_id" works..

Edit: Got it to work.

I just binded the field on the form to the proper ones on the model and now i have the data =)

"> "llamada_contacto_id", :with => "empresa_id", :url => { :controller => "contactos", :action => "get_contactos" } %>

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜