Module: Outpost::Model::Routing
- Extended by:
- ActiveSupport::Concern
- Defined in:
- lib/outpost/model/routing.rb
Overview
Routing
Provides easy access to any object’s admin paths, and any class’s admin paths.
These methods are just delegations to your app’s routes.
Provides alias methods for non-GET routes:
-
admin_index_path => admin_create_path
-
admin_show_path => admin_update_path, admin_destroy_path
So you can do, for example:
POST admin_create_path
Which would make more sense than ‘POST admin_index_path`, even though they are the same path.
Defined Under Namespace
Modules: ClassMethods
Instance Method Summary collapse
-
#admin_edit_path ⇒ Object
/outpost/blog_entries/20/edit.
- #admin_edit_url ⇒ Object
-
#admin_show_path ⇒ Object
(also: #admin_update_path, #admin_destroy_path)
/outpost/blog_entries/20.
- #admin_show_url ⇒ Object (also: #admin_update_url, #admin_destroy_url)
-
#public_path(options = {}) ⇒ Object
(also: #link_path)
Uses self.class.public_route_key to generate the front-end path to this object If an object doesn’t have a front-end path, do not define a public_route_key on the class.
- #public_url(options = {}) ⇒ Object (also: #remote_link_path)
-
#route_hash ⇒ Object
Override this method manually for each model.
Instance Method Details
#admin_edit_path ⇒ Object
/outpost/blog_entries/20/edit
74 75 76 |
# File 'lib/outpost/model/routing.rb', line 74 def admin_edit_path member_route("edit_outpost_#{self.class.singular_route_key}_path") end |
#admin_edit_url ⇒ Object
79 80 81 |
# File 'lib/outpost/model/routing.rb', line 79 def admin_edit_url member_route("edit_outpost_#{self.class.singular_route_key}_url") end |
#admin_show_path ⇒ Object Also known as: admin_update_path, admin_destroy_path
/outpost/blog_entries/20
85 86 87 |
# File 'lib/outpost/model/routing.rb', line 85 def admin_show_path member_route("outpost_#{self.class.singular_route_key}_path") end |
#admin_show_url ⇒ Object Also known as: admin_update_url, admin_destroy_url
93 94 95 |
# File 'lib/outpost/model/routing.rb', line 93 def admin_show_url member_route("outpost_#{self.class.singular_route_key}_url") end |
#public_path(options = {}) ⇒ Object Also known as: link_path
Uses self.class.public_route_key to generate the front-end path to this object If an object doesn’t have a front-end path, do not define a public_route_key on the class.
If the object isn’t public, then leave route_hash empty as well.
108 109 110 111 112 113 |
# File 'lib/outpost/model/routing.rb', line 108 def public_path(={}) if self.route_hash.present? && self.class.public_route_key Rails.application.routes.url_helpers.send( "#{self.class.public_route_key}_path", .merge!(self.route_hash)) end end |
#public_url(options = {}) ⇒ Object Also known as: remote_link_path
130 131 132 133 134 135 |
# File 'lib/outpost/model/routing.rb', line 130 def public_url(={}) if path = self.public_path() File.join( "http://#{Rails.application.[:host]}", path) end end |
#route_hash ⇒ Object
Override this method manually for each model. If the object isn’t public, then don’t override this method. #public_path checks for the presence of this object. By leaving it blank, you’re also telling #public_path to be nil.
124 125 126 |
# File 'lib/outpost/model/routing.rb', line 124 def route_hash {} end |