steveyang
steveyang

Reputation: 9298

How could I access view helpers in Model

Given I've defined this in the config/routes.rb

resource :products

If I want to access the route helpers such as product_path(self) to generate urls in the Model. How could I mixin those modules in ?

Upvotes: 0

Views: 825

Answers (1)

dimuch
dimuch

Reputation: 12818

class MyClass < ActiveRecord::Base
  include Rails.application.routes.url_helpers
end

or (without inclusion)

Rails.application.routes.url_helpers.product_path(self)

Upvotes: 3

Related Questions