【问题标题】:i received this error 'Unpermitted parameter: image' in nested parameter我在嵌套参数中收到此错误“未经许可的参数:图像”
【发布时间】:2016-07-31 09:38:01
【问题描述】:

这是我的 profiles_controller.rb

 def create

 @profile = current_user.build_profile(profile_params)

  if @profile.save
  else
    render :new 
  end
 end
 end

profile.rb 具有来自 image.rb

的嵌套属性
  params.require(:profile).permit(:first_name, :last_name, :phone_no, image_attributes: [:id,:image,:imageable_id,:imageable_type])

这是 profile.rb

 class Profile < ActiveRecord::Base
 belongs_to :user
 has_one :image , :as => :imageable
 accepts_nested_attributes_for :image
 end

这是 image.rb

  class Image < ActiveRecord::Base
  belongs_to :imageable, polymorphic: true
  mount_uploader :image, ImageUploader
   end

这是 profile.rb 模型中的 _form.html.erb

   <%= f.fields_for :image do |ff| %>
   <%= f.label :image %>
   <%= f.file_field :image %>
   <% end %>

【问题讨论】:

    标签: ruby-on-rails nested-attributes


    【解决方案1】:
    <%= f.fields_for :image do |ff| %>
      <%= ff.label :image %> 
      <%= ff.file_field :image %>
    <% end %>
    

    【讨论】:

      猜你喜欢
      • 2014-05-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-07-13
      • 1970-01-01
      • 2016-03-20
      相关资源
      最近更新 更多