Let’s say we are adding a basic signing functionality to our application and we want the current_user(which is under User Controller) should be available for other Model file. We have a model called Comment and we wish to make current_user accessible here.
Inside app/views/controller/ApplicationController.rb define a method which assigns current_user to a cattr_accessible attribute defined in Model :
class Comment < ActiveRecord::Base
# this cattr_accessor attribute now holds current_user attr_accessible :commenter
self.commenter = self.user.name
#now we can treat user as our current_user
We have assigned thise current_user to an attribute in Comment.rb model file and used it.