Q:

Is it possible to use the 'request' method in a model? 

I am using Ruby on Rails 3 and I am tring to do some like this in my model file
if request.headers["CONTENT_LENGTH"]
  ...
end

but I get this error:
NameError (undefined local variable or method `request' for #<User:0x00...>):

So, is it possible to use the 'request' method in a model?  If so, how? 

A:

No, because the request is only available in controllers and view code.  From a design point of view you're ill advised to use the request within model code, but let's say you want to do something with the request on a particular instance of your User, just create a method for it:
class User
  ...
  def has_a_request?(request)
    raise ArgumentError if(request.blank?  || ! request.respond_to(:headers))
    if(request.headers["CONTENT_LENGTH"] # Does it really have CONTENT_LENGTH btw? 
      puts "#{self.username} got a request with content length"
      return true
    else
      puts "#{self.username} didn't get a request with content length"
      return false
    end
  end

And then elsewhere in your application:
User.has_a_request?(request)

