2016-07-31 60 views
-1

这是我的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 

这是_form.html.erbprofile.rb模型

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

回答

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

thnks @Sergey索科洛夫解决了这个 – fahad