Таким образом, я получил ниже хэш:ActiveModel :: ForbiddenAttributesError без сильных параметров
hash = {
"role"=>"#",
"city"=>"#",
"listing_attributes"=>
{
"desks_attributes"=>
{
"0"=>{"quantity_available"=>"#"}
}
},
"username"=>"#",
"email"=>"#",
"fullname"=>"#",
"password"=>"#",
"password_confirmation"=>"#",
"terms"=>"#"
}
И я пытаюсь построить модель пользователя объекта:
User.new(
:username => hash[:username],
:fullname => hash[:fullname],
:first_name => hash[:first_name],
:last_name => hash[:last_name],
:email => hash[:email],
:password => hash[:password],
:password_confirmation => hash[:password_confirmation],
:role => hash[:role],
:city => hash[:city],
:terms => hash[:terms],
:listing_attributes => hash[:listing_attributes]
)
И, кажется, чтобы вернуться в следующем ActiveModel :: ForbiddenAttributesError, я понимаю, что эта ошибка может поднять голову при использовании сильных параметров, но я не могу тренироваться, как обойти ее, если не использовать сильные параметры? Или есть способ, который я могу включить в этот код сильные параметры?
Для записи я получил следующие модели:
class Desk < ActiveRecord::Base
belongs_to :listing
has_one :user, through: :listing
end
class Listing < ActiveRecord::Base
belongs_to :user
has_many :desks, dependent: :destroy
accepts_nested_attributes_for :user, :desks
end
class User < ActiveRecord::Base
has_one :listing, dependent: :destroy
has_many :desks, :through => :listing
accepts_nested_attributes_for :listing
end
И я следующий набор для моих сильных параметров:
params.require(:user).permit(:username, :fullname, :first_name, :last_name,:email, :password, :password_confirmation,:password_digest, :role, :city, :terms,listing_attributes: [:company_name, :address, :post_code, :user_id, :city, :latitude, :longitude, desks_attributes: [:quantity_available]])
Если вы посмотрите в development.log, вы обычно видите, что PARAMS не в белый список. Будет ли это намек? –