Class: ActiveRecordJsonUrlExtension::UrlHelper

Inherits:
Object
  • Object
show all
Includes:
ActionDispatch::Routing::UrlFor
Defined in:
app/models/active_record_json_url_extension.rb

Overview

The following class generates a scope that prevents the url helpers from being included directly into ActiveRecordJsonUrlExtension and therefore into ActiveRecord::Base.

class MyModel < ActiveRecord::Base
end

my_instance = MyModel.create()

You may call ‘my_instance.url()` to get the same result as for `url_for(my_instance)`. But you should not be able to call, for example, `my_instance.my_model_path( … )`.

Instance Method Summary collapse

Constructor Details

#initialize(obj) ⇒ UrlHelper

Returns a new instance of UrlHelper.



34
35
36
# File 'app/models/active_record_json_url_extension.rb', line 34

def initialize(obj)
  @obj = obj
end

Instance Method Details

#urlObject



42
43
44
# File 'app/models/active_record_json_url_extension.rb', line 42

def url
  url_for(@obj)
end

#url_optionsObject



38
39
40
# File 'app/models/active_record_json_url_extension.rb', line 38

def url_options
  Rails.application.config.action_mailer.default_url_options || raise("Please set 'config.action_mailer.default_url_options = {host: ...}' in the application config.")
end