我想从模型的类方法生成 url。我之前通过简单地包含在实例方法中完成了此操作ActionController::UrlWriter
- 我尝试将其包含在实例定义范围和类定义范围中,但无济于事。
class Foo < ActiveRecord::Base
# only works for instance methods
# include ActionController::UrlWriter
class << self
# results in this error: undefined method `default_url_options' for Class:Class
# include ActionController::UrlWriter
def my_method
return user_sprockets_url(:thingy => 'blue')
end
end
end