exist any way to have in my own function in model the request.request_uri?
Now 开发者_C百科I have in model called Func.rb this:
class Func
def self.url_adr
request.request_uri
end
end
But I am getting an error undefined local variable or method `request' for Func:Class
The request object is available from controllers. I suppose you could pass it in as an argument to a model if you must, e.g.
##### in controller
Func.url_addr(request)
##### in model
def self.url_adr(controller_request)
controller_request.request_uri
end
However, Ian has a good point, request data is not usually associated with models.
精彩评论