0
我有一個訂單模型和一個客戶模型,使訂單belongs_to Customer。我正在使用rails-jquery-autocomplete gem,我試圖用belongs_to關聯來構建表單。我設法讓客戶從訂單一側正確保存,但現在如果您在編輯過程中查看錶單,則會顯示此內容。Ruby on Rails,Jquery自動完成不能正確顯示名稱
我很想爲它顯示客戶名稱。但我不確定該從哪裏出發。
這是表單的該部分的視圖。
.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