#ruby-on-rails #jsonb
Вопрос:
У меня есть модель пользователя с полем jsonb в атрибуте профиля
В моем профиле базы данных :
t.jsonb "options", default: {"display_name"=>"0", "display_country"=>"1", "display_profile"=>"1", "display_birthday"=>"1"}
В моей пользовательской модели
class User < ApplicationRecord #:nodoc:
has_one :profile, inverse_of: :user, dependent: :destroy
accepts_nested_attributes_for :profile
end
В моем пользовательском контроллере
class UsersController < ApplicationController
def update
if @user.update(user_params)
redirect_to edit_user_path(@current_user.slug), notice: t('users.user_updated')
else
render :edit, p: params[:p]
end
end
def user_params
params.require(:user).permit(
:email,
:pseudo,
profile_attributes: [
.....
options: %i[display_profile display_name display_birthday display_country]
])
end
Когда я хочу обновить своего @пользователя, я получаю сообщение об ошибке :
@errors=[#<ActiveModel::Error attribute=base, type=Please enter correct values, options={}>,
#<ActiveModel::NestedError attribute=profile.user.base, type=Please enter correct values, options={}>]>
параметры пользователя
=> #<ActionController::Parameters {"profile_attributes"=>#<ActionController::Parameters {"id"=>"141", "options"=>#<ActionController::Parameters {"display_profile"=>"true", "display_name"=>"1", "display_birthday"=>"true", "display_country"=>"true"} permitted: true>} permitted: true>} permitted: true>
>>
Как я могу исправить эту ошибку ?