module Outpost::Model::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
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.
Public Instance Methods
/outpost/blog_entries/20/edit
# File lib/outpost/model/routing.rb, line 74 def admin_edit_path member_route("edit_outpost_#{self.class.singular_route_key}_path") end
kpcc.org/outpost/blog_entries/20/edit
# File lib/outpost/model/routing.rb, line 79 def admin_edit_url member_route("edit_outpost_#{self.class.singular_route_key}_url") end
/outpost/blog_entries/20
# File lib/outpost/model/routing.rb, line 85 def admin_show_path member_route("outpost_#{self.class.singular_route_key}_path") end
kpcc.org/outpost/blog_entries/20
# File lib/outpost/model/routing.rb, line 93 def admin_show_url member_route("outpost_#{self.class.singular_route_key}_url") end
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.
# File lib/outpost/model/routing.rb, line 108 def public_path(options={}) if self.route_hash.present? && self.class.public_route_key Rails.application.routes.url_helpers.send( "#{self.class.public_route_key}_path", options.merge!(self.route_hash)) end end
# File lib/outpost/model/routing.rb, line 130 def public_url(options={}) if path = self.public_path(options) File.join( "http://#{Rails.application.default_url_options[:host]}", path) end end
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.
# File lib/outpost/model/routing.rb, line 124 def route_hash {} end
Private Instance Methods
Don't try to build a route if the ID is nil. Should we instead be checking persistence?
# File lib/outpost/model/routing.rb, line 145 def member_route(name) if self.id Rails.application.routes.url_helpers.send(name, self.id) end end