【问题标题】:How to update two f.select from 2 different tables on ruby on rails如何从 ruby​​ on rails 上的 2 个不同表中更新两个 f.select
【发布时间】:2011-02-08 14:53:52
【问题描述】:

我刚开始从事 Ruby On Rails 项目,我需要查看公司的联系人。

一旦选择了公司,它们就会出现..

<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} %>

但是什么也没发生,我什至在脚本/服务器上都看不到错误。

有人能指出我正确的方向吗?

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

我在链接上看到一个人做了我需要的完全相同的事情,但没有发布任何信息。

干杯。

【问题讨论】:

    标签: ruby-on-rails


    【解决方案1】:

    有点让这个工作..这是我的更新..

    这是放置我的选择框的表单:

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

    contactos控制器上的get_contactos函数:

    def get_contactos @contacto = Contacto.find_all_by_empresa_id(params[:empresa_id]) 渲染:布局 => 假 结束

    还有视图get_contactos.rhtml(contactos):

    ">%>

    我只需要将表单绑定到正确的字段即可完成。

    我无法通过观察字段 :empresa_id 但“empresa_id”工作..

    编辑:让它工作。

    我刚刚将表单上的字段绑定到模型上的正确字段,现在我有了数据 =)

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2010-10-20
      • 1970-01-01
      • 2011-06-19
      • 1970-01-01
      • 2013-05-20
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多