Module: Cms::RouteExtensions

Defined in:
lib/cms/route_extensions.rb

Instance Method Summary collapse

Instance Method Details

#content_blocks(content_block_name, options = {}, &block) ⇒ Object

Adds all necessary routes to manage a new content type. Works very similar to the Rails resources method, adding basic CRUD routes, as well as additional ones

for CMS specific routes (like versioning)

Parameters:

  • content_block_name (Symbol)
    • The plural name of a new Content Type. Should match the name of the model_class, like :dogs or :donation_statuses



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/cms/route_extensions.rb', line 8

def content_blocks(content_block_name, options={}, & block)
  model_class = guess_model_class(content_block_name)

  resources content_block_name do
    member do
      put :publish if model_class.publishable?
      if model_class.versioned?
        get :versions
        get 'version/:version', to: "#{content_block_name}#version", as: 'version'
        put 'revert_to/:version', to: "#{content_block_name}#revert_to", as: 'revert'
      end
    end
    collection do
      put :update, to: "#{content_block_name}#bulk_update"
    end
  end
end

#mount_browsercmsObject Also known as: routes_for_browser_cms

Adds the routes required for BrowserCMS to function to a routes.rb file. Should be the last route in the file, as all following routes will be ignored.

Usage:

YourAppName::Application.routes.draw do
   match '/some/path/in/your/app' :to=>"controller#action''
   mount_browsercms
end


35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/cms/route_extensions.rb', line 35

def mount_browsercms

  mount Cms::Engine => "/cms", :as => "cms"

  add_page_routes_defined_in_database

  # Add User management features
  devise_for :cms_user,
             class_name: Cms.user_class_name,
             path: '',
             skip: :password,
             path_names: {sign_in: 'login'},
             controllers: {sessions: 'cms/sites/sessions'}

  devise_scope :cms_user do
    get '/forgot-password' => "cms/sites/passwords#new", :as => 'forgot_password'
    post '/forgot-password' => "cms/sites/passwords#create", as: 'cms_user_password'
    get '/passwords/:id/edit' => "cms/sites/passwords#edit", as: 'edit_password'
    put '/forgot-password' => "cms/sites/passwords#update", as: 'update_password'
  end

  # Handle 'stock' attachments
  get "/attachments/:id/:filename", :to => "cms/attachments#download"
  get "/", :to => "cms/content#show"

  # Only need :POST to support  portlets that are acting like controllers.
  # Ideally we could get rid of this need.
  match "*path", :to => "cms/content#show", via: [:get, :post]
end