我的内裤扭曲了。我的目标是让任何登录的人都能够编辑指南。show 操作将显示 updated_by 和 created_by 用户。有什么不对劲。
指南控制器.rb
before_filter :authenticate_user!, only: [:new, :create, :edit, :update]
def update
@guideline = Guideline.find(params[:id])
respond_to do |format|
if @guideline.update_attributes(params[:guideline])
@guideline.update_attribute(:updated_by, current_user.id)
def show
@guideline = Guideline.find(params[:id])
if @guideline.updated_by
@updated = User.find(@guideline.updated_by).profile_name
end
if User.find(@guideline.user_id)
@created = User.find(@guideline.user_id).profile_name
end
指南.rb(模型)
attr_accessible :content, :hospital, :title, :user_id, :guideline_id, :specialty, :updated_by, :current_user
belongs_to :user
has_many :favourite_guidelines
我似乎能够正确分配 updated_by 。但是当我进入管理员并尝试更改指南用户时,我得到了错误:
Processing by Admin::GuidelinesController#update as HTML
Parameters: {"utf8"=>"✓", "authenticity_token"=>"x+2BC0ztrqLBasL5uWskDEdars+FvSSNRvzGJuXyiA0=", "guideline"=>{"user_id"=>"13", "title"=>"URL testing", "content"=>"http://www.healme.com", "hospital"=>"Children's Hospital", "subtitle"=>"", "specialty"=>"Cardiology", "slug"=>"", "updated_by"=>""}, "commit"=>"Update Guideline", "id"=>"37-url-testing"}
AdminUser Load (0.4ms) SELECT "admin_users".* FROM "admin_users" WHERE "admin_users"."id" = 1 LIMIT 1
Guideline Load (0.2ms) SELECT "guidelines".* FROM "guidelines" WHERE "guidelines"."id" = ? LIMIT 1 [["id", "37-url-testing"]]
Completed 500 Internal Server Error in 9ms
ActiveModel::MassAssignmentSecurity::Error (Can't mass-assign protected attributes: subtitle, slug):
这是 before_filter 的问题吗?