在我的 Rails 应用程序中,我有一个用户模型,其中有一个属性:点
class User < ActiveRecord::Base
attr_accessible :points
has_many :answers
end
有没有办法让属性只从特定的控制器动作更新?
class AnswersController < ApplicationController
....
def create
@user = current_user
@answer = @user.answers.build(params[:answer])
if @answer.save
@user.points += 10 # <-- I want to make points updatable only from this action
@user.save
else
...
end
...
end