How can I properly use Rails routes in a service class?
I'm trying to use Rails routes outside the Rails commons classes, like controllers, views and even models. I was able to make it work with this code:
class SomeSer开发者_开发问答vice
include Rails.application.routes.url_helpers
default_url_options[:host] = 'localhost'
def myMethod
my_resource_url(:id => 1)
end
end
SomeService#myMethod works as expected in my tests classes, returning url like: http://localhost/myresource/1
But when I run rails server I can't get the actual host and port. How can I solve this?
精彩评论