0
Я получаю сообщение об ошибке в своей заявке undefined method 'preference' for #<User:0x007fb3cc1c3b80>
. Вслед были мои accounts
контроллера:Rails undefined method ReactJS
class AccountsController < ApplicationController
before_action :authenticate_user!
def edit
#render html: 'Edit your account'
render component: 'AccountsEdit', props: {
preference: PreferenceSerializer.new(current_user.preference)
}, tag: 'div'
end
def update
@preference = current_user.preference
if @preference.update_attributes(preference_params)
render json: { data: 'SUCCESS!' }
else
render json: { data: 'FAIL!' }
end
end
private
def preference_params
params.require(:preference).permit(:display_name, :notify_on_answer, :daily_digest)
end
end
И мой пользователь и предпочтение модель:
class User < ActiveRecord::Base
# Include default devise modules. Others available are:
# :confirmable, :lockable, :timeoutable and :omniauthable
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable
end
class Preference < ActiveRecord::Base
belongs_to :user
end
Кажется, все выглядят хорошо, но я постоянно получаю ту же ошибку. Я что-то пропустил? Благодаря!!
вам не хватает, как пользователь связан с предпочтениями, как has_many: предпочтения или has_a: предпочтение линии в модели пользователя. – uday
@ d3bug3r, Если вы чувствуете, что мой ответ помог [решить вашу проблему] (http://stackoverflow.com/help/someone-answers), отметьте его как «[принято] (http://stackoverflow.com/help/ принятый-ответ), нажав зеленую галочку рядом с ответом, чтобы переключить ее с серых на заполненные. Это поможет сообществу сосредоточиться на неотвеченных вопросах. – Lahiru