开发者

Rails 3 - request.request_uri in model

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜