我知道这里有很多这样的帖子,我认为我已经阅读并尝试了其中的每一个,都没有成功。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