【问题标题】:Ruby on rails, Jquery autocomplete not showing names correctlyRuby on rails,Jquery 自动完成未正确显示名称
【发布时间】:2015-06-22 21:41:20
【问题描述】:

我有一个订单模型和一个客户模型,这样订单就属于客户。我正在使用rails-jquery-autocomplete gem 并且我正在尝试构建一个带有belongs_to 关联的表单。我设法让客户从订单端正确保存,但现在如果您在编辑期间查看表单,它会显示这一点。

我希望它显示客户姓名。但我不确定从这里去哪里。

这是表单该部分的视图。

.panel.panel-default
    .panel-heading
      =f.label :customer
    .panel-body
      =f.autocomplete_field :customer, :autocomplete_customer_name, placeholder: 'Customer', id_element: "#customer_id"
      =f.hidden_field :customer_id, id:"customer_id"
      =link_to "new customer", new_customer_path, class: "new_customer_link"

这是表单的控制器:

class OrderssController < ApplicationController
  autocomplete :customer, :name
  before_action :set_order, only: [:show, :edit, :update, :destroy, :toggle]
...

def rfq_params
      params.require(:order).permit(:customer_id, :due, :ship_date, :is_budgetary, :notes, :end_user, :application, :mandatory_due_date, :tag_list)

以下是相关模型:

class Order < ActiveRecord::Base
    has_many :valves, :class_name => "Valve"
    accepts_nested_attributes_for :valves, :allow_destroy => true
    belongs_to :customer

class Customer < ActiveRecord::Base
    has_many :orders
    belongs_to :company
end

【问题讨论】:

    标签: jquery ruby-on-rails autocomplete


    【解决方案1】:

    所以我无法“正常”工作,而是在订单中添加了 customer_name 属性。并改变了

    =f.autocomplete_field :customer, :autocomplete_customer_name, placeholder: 'Customer', id_element: "#customer_id"
    

    =f.autocomplete_field :customer_name, :autocomplete_customer_name, placeholder: 'Customer', id_element: "#customer_id"
    

    这很不幸,但它得到了预期的结果。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-18
      • 1970-01-01
      • 2016-09-22
      • 2012-06-08
      • 2018-09-16
      相关资源
      最近更新 更多