Class: ActionDispatch::Routing::Mapper

Inherits:
Object
  • Object
show all
Defined in:
lib/comfy_blog/routes/blog_admin.rb,
lib/comfy_blog/routes/blog.rb

Instance Method Summary collapse

Instance Method Details

#comfy_route_blog(options = {}) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/comfy_blog/routes/blog.rb', line 3

def comfy_route_blog(options = {})
  options[:path] ||= 'blog'
  path = ['(:cms_path)', options[:path], '(:blog_path)'].join('/')
  
  namespace :blog, :path => path, :constraints => {:blog_path => /\w[a-z0-9_-]*/} do
    with_options :constraints => {:year => /\d{4}/, :month => /\d{1,2}/} do |o|
      o.get ':year'               => 'posts#index', :as => :posts_of_year
      o.get ':year/:month'        => 'posts#index', :as => :posts_of_month
      o.get ':year/:month/:slug'  => 'posts#show',  :as => :posts_dated
    end
    post ':slug/comments' => 'comments#create', :as => :comments
    get  ':slug'          => 'posts#serve',     :as => :post
    get  '/'              => 'posts#serve',     :as => :posts
  end
end

#comfy_route_blog_admin(options = {}) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/comfy_blog/routes/blog_admin.rb', line 3

def comfy_route_blog_admin(options = {})
  options[:path] ||= 'admin'
  path = [options[:path], 'sites', ':site_id'].join('/')
  
  scope :module => :admin do
    namespace :blog, :as => :admin, :path => path, :except => [:show] do
      resources :blogs do
        resources :posts
        resources :comments, :only => [:index, :destroy] do
          patch :toggle_publish, :on => :member
        end
      end
    end
  end
end