我知道這裏有很多這樣的帖子,我認爲我已經閱讀並嘗試了其中的每一個,都沒有成功。rails 4不允許的參數嵌套形式
我有Post和Image模型,我需要與多對一的關係一起工作。
class Post < ActiveRecord::Base
has_many :images
end
class Image < ActiveRecord::Base
belongs_to :post
mount_uploader :file, images_uploader
end
這是在我的職位控制器,其中包括我的圖像模型遷移所有字段的post_parms聲明。
private
def post_params
params.require(:post).permit(:title, :content, image_attributes: [:id, :post_id, :file])
end
這裏是我的後期創建表單,其中,我希望允許多個圖像資產創建與每個職位。
<%= form_for @post, html: {class: "pure-form pure-form-stacked"} do |post| %>
<%= post.fields_for :image, :html => { :multipart => true } do |image| %>
<%= image.label :file, "Upload Image:" %>
<%= image.file_field :file, multiple: true %>
<% end %>
<fieldset class="post-form">
<%= post.label :title %>
<%= post.text_field :title %>
<%= post.label :content %>
<%= post.text_area :content, :class => "redactor", :rows => 40, :cols => 120 %>
</fieldset>
<div class = "button-box">
<%= post.submit class: "pure-button pure-button-primary" %>
<%= link_to "Cancel", posts_path, :class => "pure-button" %>
</div>
儘管一再努力和閱讀每一個崗位,我可以找到關於這個話題,我仍然得到:
Unpermitted parameters: image
這裏的問題是,這個錯誤沒有提供線索從哪裏開始尋找爲了這個問題。因爲我不確定下一步該去哪裏,所以我想我會在這裏發佈,尋找更多的專業意見。
問題解決了嗎?如果沒有,你可以分享PostController的內容嗎? – HackerKarma