Ruby on rails 我收到了这个错误';不允许的参数:image';嵌套参数中的
这是我的配置文件\u controller.rbRuby on rails 我收到了这个错误';不允许的参数:image';嵌套参数中的,ruby-on-rails,nested-attributes,Ruby On Rails,Nested Attributes,这是我的配置文件\u controller.rb def create @profile = current_user.build_profile(profile_params) if @profile.save else render :new end end end params.require(:profile).permit(:first_name, :last_name, :phone_no, image_attributes: [:id,:im
def create
@profile = current_user.build_profile(profile_params)
if @profile.save
else
render :new
end
end
end
params.require(:profile).permit(:first_name, :last_name, :phone_no, image_attributes: [:id,:image,:imageable_id,:imageable_type])
class Profile < ActiveRecord::Base
belongs_to :user
has_one :image , :as => :imageable
accepts_nested_attributes_for :image
end
class Image < ActiveRecord::Base
belongs_to :imageable, polymorphic: true
mount_uploader :image, ImageUploader
end
profile.rb具有来自image.rb的嵌套属性
def create
@profile = current_user.build_profile(profile_params)
if @profile.save
else
render :new
end
end
end
params.require(:profile).permit(:first_name, :last_name, :phone_no, image_attributes: [:id,:image,:imageable_id,:imageable_type])
class Profile < ActiveRecord::Base
belongs_to :user
has_one :image , :as => :imageable
accepts_nested_attributes_for :image
end
class Image < ActiveRecord::Base
belongs_to :imageable, polymorphic: true
mount_uploader :image, ImageUploader
end
这是profile.rb
def create
@profile = current_user.build_profile(profile_params)
if @profile.save
else
render :new
end
end
end
params.require(:profile).permit(:first_name, :last_name, :phone_no, image_attributes: [:id,:image,:imageable_id,:imageable_type])
class Profile < ActiveRecord::Base
belongs_to :user
has_one :image , :as => :imageable
accepts_nested_attributes_for :image
end
class Image < ActiveRecord::Base
belongs_to :imageable, polymorphic: true
mount_uploader :image, ImageUploader
end
类配置文件:imageable
接受\u嵌套的\u属性\u:image
结束
这是image.rb
def create
@profile = current_user.build_profile(profile_params)
if @profile.save
else
render :new
end
end
end
params.require(:profile).permit(:first_name, :last_name, :phone_no, image_attributes: [:id,:image,:imageable_id,:imageable_type])
class Profile < ActiveRecord::Base
belongs_to :user
has_one :image , :as => :imageable
accepts_nested_attributes_for :image
end
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 %>