좋은 밤 친구!check_boxes 오류가있는 simple_fields_for 오류
많이 쓰이는 양식에서 확인란과 필드 옆에 주어진 클래스 (도구)의 모든 개체를 표시해야합니다.
= simple_form_for @service, html: { class: 'form-horizontal' } do |f|
- @tools.each do |tool|
= f.simple_fields_for :instrumentalisations, tool do |i|
= i.input :tool_id, tool.id, as: :check_boxes
= i.input :amount
그러나 나는 다음과 같은 오류를 받고 있어요 : 다음과 같이 내 형태는
Undefined method `tool_id 'for # <Tool: 0x007faef0327c28>
Did you mean To_gid
모델
class Service < ApplicationRecord
has_many :partitions, class_name: "Partition", foreign_key: "service_id"
has_many :steps, :through => :partitions
has_many :instrumentalisations
has_many :tools, :through => :instrumentalisations
accepts_nested_attributes_for :instrumentalisations
end
class Tool < ApplicationRecord
has_many :instrumentalisations
has_many :services, :through => :instrumentalisations
accepts_nested_attributes_for :services
end
class Instrumentalisation < ApplicationRecord
belongs_to :service
belongs_to :tool
end
컨트롤러
def new
@service = Service.new
@service.instrumentalisations.build
end
def edit
@tools = Tool.all
end
def create
@service = Service.new(service_params)
respond_to do |format|
if @service.save
format.html { redirect_to @service, notice: 'Service was successfully created.' }
format.json { render :show, status: :created, location: @service }
else
format.html { render :new }
format.json { render json: @service.errors, status: :unprocessable_entity }
end
end
end
def service_params
params.require(:service).permit(:name, :description, :price, :runtime, :status, step_ids: [], instrumentalisations_attributes: [ :id, :service_id, :tool_id, :amount ])
end
감사합니다!
외래 키인이 필드 : tool_id가 뭔가 방해를 받습니까? – wilfrank
나는 눈치 내가 '= f.simple_fields_for에서 변경할 때 : instrumentalisations, 도구 할 | I |' 에 '= f.simple_fields_for : instrumentalisations가 할 | I |' 는 여러 도구 객체에 저를 소개합니다 , 중복 것처럼 보입니다 – wilfrank