代码之家  ›  专栏  ›  技术社区  ›  fahad

我在嵌套参数中收到错误“Unpermitted parameter:image”

  •  -1
  • fahad  · 技术社区  · 8 年前

    这是我的 配置文件_控制器.rb

     def create
    
     @profile = current_user.build_profile(profile_params)
    
      if @profile.save
      else
        render :new 
      end
     end
     end
    

    剖面.rb 具有来自的嵌套属性 图像.rb

      params.require(:profile).permit(:first_name, :last_name, :phone_no, image_attributes: [:id,:image,:imageable_id,:imageable_type])
    

    这是 剖面.rb

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

    这是 图像.rb

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

    这是 _表单.html erb 从…起 剖面.rb 模型

       <%= f.fields_for :image do |ff| %>
       <%= f.label :image %>
       <%= f.file_field :image %>
       <% end %>
    
    1 回复  |  直到 8 年前
        1
  •  0
  •   Sergey Sokolov    8 年前
    <%= f.fields_for :image do |ff| %>
      <%= ff.label :image %> 
      <%= ff.file_field :image %>
    <% end %>