Posted almost 11 years ago. Visible to the public. Repeats.
How to use Rails URL helpers in any Ruby class
In Rails 3+, you can use:
Copyclass Project delegate :url_helpers, to: 'Rails.application.routes' def project_path url_helpers.project_path(self) end end
For Rails 2, use the attached
Modularity
Archive
trait. It will give any Ruby class a method #url_writer
, on which you can call URL helpers:
Copyclass Foo does 'write_urls' def self.class_method url_writer.session_path end def instance_method url_writer.project_path(5) end end
Does your version of Ruby on Rails still receive security updates?
Rails LTS provides security patches for unsupported versions of Ruby on Rails (2.3, 3.2, 4.2 and 5.2).