module Outpost::Model::Routing

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:

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

admin_destroy_path()
Alias for: admin_show_path
admin_destroy_url()
Alias for: admin_show_url
admin_edit_path() click to toggle source

/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
admin_edit_url() click to toggle source

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
admin_show_path() click to toggle source

/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
admin_show_url() click to toggle source

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
admin_update_path()
Alias for: admin_show_path
admin_update_url()
Alias for: admin_show_url
public_path(options={}) click to toggle source

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
Also aliased as: link_path
public_url(options={}) click to toggle source

scpr.org/blogs/2012/…

# 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
Also aliased as: remote_link_path
route_hash() click to toggle source

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

member_route(name) click to toggle source

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