我已經得到了我的內褲。我的目標是登錄的任何人都可以編輯指南。 show動作將顯示updated_by和created_by用戶。有些事情是不對的。無法在Rails控制器中批量分配屬性
guidelines_controller.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
guidelines.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這是一個問題用?