我已經嵌套在我的表格屬性和2款 - 藝術品和ArtDescription,其連接HAS_ONE/belongs_to的,但我有錯誤的ActiveRecord :: AssociationTypeMismatch Rails中4
的ActiveRecord :: AssociationTypeMismatch在ArtworksController#創建 ArtDescription(#30842620)預期,得到了 的ActionController ::參數(#9409680)
什麼錯?
表格
<%= form_for :artwork, url: artworks_path do |f| %>
<p>
name:<%= f.text_field :name %></br>
author:<%= f.text_field :author %></br>
date:<%= f.text_field :date %></br>
museum:<%= f.text_field :museum %></br>
place:<%= f.text_field :create_place %></br>
comment:<%= f.text_field :comment %></br>
</p>
<p>
<%= f.fields_for :art_description do |artdesc|%>
type:<%= artdesc.text_field :type %></br>
base:<%= artdesc.text_field :base %></br>
style:<%= artdesc.text_field :style %></br>
genre:<%= artdesc.text_field :genre %></br>
plot:<%= artdesc.text_field :plot %></br>
reference: <%= artdesc.text_field :reference %></br>
format_weight: <%= artdesc.text_field :format_weight%></br>
format_height:<%= artdesc.text_field :format_height %></br>
<% end %>
<%= f.submit ('Ok')%> </p>
<% end %>
控制器ArtworksController
def create
@artwork = Artwork.create(artwork_params)
if @artwork.save
redirect_to artwork_path(@artwork)
else
render 'new'
end
end
模型
class Artwork < ActiveRecord::Base
has_one :art_description
accepts_nested_attributes_for :art_description
end
斯特朗Parametrs
def artwork_params
params.require(:artwork).permit(:name, :author, :date, :museum, :comment, :create_place, art_description: [ :type, :base, :style, :genre, :plot, :reference, :format_weight, :format_height])
end
的可能的複製[?爲什麼我創建的模型對象時,我得到一個AssociationTypeMismatch(http://stackoverflow.com/questions/2663141/why -DO-I-GET-A-associationtypemismatch-時創造的,我的模型對象)。具體而言,接受的答案可能會產生您正在尋找的解決方案。 –