No route matches in rails 4 Comfortable Mexican So

2019-09-05 21:41发布

问题:

I am using comfortable mexican sofa CMS. Added the gem to an existing application. Following the documentation from github, after it's installation I placed the route

comfy_route :cms_admin, :path => '/cms'

as first route and

comfy_route :cms_admin, :path => '/cms'

as last route.

Here's the result shown when I do rake rotues i.e. I see all the routes generated by CMS:

Prefix Verb     URI Pattern                                                               Controller#Action
                             admin_cms GET      /great(.:format)                                                          admin/cms/base#jump
       form_blocks_admin_cms_site_page GET      /great/sites/:site_id/pages/:id/form_blocks(.:format)                     admin/cms/pages#form_blocks
     toggle_branch_admin_cms_site_page GET      /great/sites/:site_id/pages/:id/toggle_branch(.:format)                   admin/cms/pages#toggle_branch
          reorder_admin_cms_site_pages PUT      /great/sites/:site_id/pages/reorder(.:format)                             admin/cms/pages#reorder
   revert_admin_cms_site_page_revision PATCH    /great/sites/:site_id/pages/:page_id/revisions/:id/revert(.:format)       admin/cms/revisions#revert
         admin_cms_site_page_revisions GET      /great/sites/:site_id/pages/:page_id/revisions(.:format)                  admin/cms/revisions#index
          admin_cms_site_page_revision GET      /great/sites/:site_id/pages/:page_id/revisions/:id(.:format)              admin/cms/revisions#show
                  admin_cms_site_pages GET      /great/sites/:site_id/pages(.:format)                                     admin/cms/pages#index
                                       POST     /great/sites/:site_id/pages(.:format)                                     admin/cms/pages#create
               new_admin_cms_site_page GET      /great/sites/:site_id/pages/new(.:format)                                 admin/cms/pages#new
              edit_admin_cms_site_page GET      /great/sites/:site_id/pages/:id/edit(.:format)                            admin/cms/pages#edit
                   admin_cms_site_page PATCH    /great/sites/:site_id/pages/:id(.:format)                                 admin/cms/pages#update
                                       PUT      /great/sites/:site_id/pages/:id(.:format)                                 admin/cms/pages#update
                                       DELETE   /great/sites/:site_id/pages/:id(.:format)                                 admin/cms/pages#destroy
          reorder_admin_cms_site_files POST     /great/sites/:site_id/files/reorder(.:format)                             admin/cms/files#reorder
                  admin_cms_site_files GET      /great/sites/:site_id/files(.:format)                                     admin/cms/files#index
                                       POST     /great/sites/:site_id/files(.:format)                                     admin/cms/files#create
               new_admin_cms_site_file GET      /great/sites/:site_id/files/new(.:format)                                 admin/cms/files#new
              edit_admin_cms_site_file GET      /great/sites/:site_id/files/:id/edit(.:format)                            admin/cms/files#edit
                   admin_cms_site_file PATCH    /great/sites/:site_id/files/:id(.:format)                                 admin/cms/files#update
                                       PUT      /great/sites/:site_id/files/:id(.:format)                                 admin/cms/files#update
                                       DELETE   /great/sites/:site_id/files/:id(.:format)                                 admin/cms/files#destroy
        reorder_admin_cms_site_layouts PUT      /great/sites/:site_id/layouts/reorder(.:format)                           admin/cms/layouts#reorder
 revert_admin_cms_site_layout_revision PATCH    /great/sites/:site_id/layouts/:layout_id/revisions/:id/revert(.:format)   admin/cms/revisions#revert
       admin_cms_site_layout_revisions GET      /great/sites/:site_id/layouts/:layout_id/revisions(.:format)              admin/cms/revisions#index
        admin_cms_site_layout_revision GET      /great/sites/:site_id/layouts/:layout_id/revisions/:id(.:format)          admin/cms/revisions#show
                admin_cms_site_layouts GET      /great/sites/:site_id/layouts(.:format)                                   admin/cms/layouts#index
                                       POST     /great/sites/:site_id/layouts(.:format)                                   admin/cms/layouts#create
             new_admin_cms_site_layout GET      /great/sites/:site_id/layouts/new(.:format)                               admin/cms/layouts#new
            edit_admin_cms_site_layout GET      /great/sites/:site_id/layouts/:id/edit(.:format)                          admin/cms/layouts#edit
                 admin_cms_site_layout PATCH    /great/sites/:site_id/layouts/:id(.:format)                               admin/cms/layouts#update
                                       PUT      /great/sites/:site_id/layouts/:id(.:format)                               admin/cms/layouts#update
                                       DELETE   /great/sites/:site_id/layouts/:id(.:format)                               admin/cms/layouts#destroy
       reorder_admin_cms_site_snippets PUT      /great/sites/:site_id/snippets/reorder(.:format)                          admin/cms/snippets#reorder
revert_admin_cms_site_snippet_revision PATCH    /great/sites/:site_id/snippets/:snippet_id/revisions/:id/revert(.:format) admin/cms/revisions#revert
      admin_cms_site_snippet_revisions GET      /great/sites/:site_id/snippets/:snippet_id/revisions(.:format)            admin/cms/revisions#index
       admin_cms_site_snippet_revision GET      /great/sites/:site_id/snippets/:snippet_id/revisions/:id(.:format)        admin/cms/revisions#show
               admin_cms_site_snippets GET      /great/sites/:site_id/snippets(.:format)                                  admin/cms/snippets#index
                                       POST     /great/sites/:site_id/snippets(.:format)                                  admin/cms/snippets#create
            new_admin_cms_site_snippet GET      /great/sites/:site_id/snippets/new(.:format)                              admin/cms/snippets#new
           edit_admin_cms_site_snippet GET      /great/sites/:site_id/snippets/:id/edit(.:format)                         admin/cms/snippets#edit
                admin_cms_site_snippet PATCH    /great/sites/:site_id/snippets/:id(.:format)                              admin/cms/snippets#update
                                       PUT      /great/sites/:site_id/snippets/:id(.:format)                              admin/cms/snippets#update
                                       DELETE   /great/sites/:site_id/snippets/:id(.:format)                              admin/cms/snippets#destroy
             admin_cms_site_categories GET      /great/sites/:site_id/categories(.:format)                                admin/cms/categories#index
                                       POST     /great/sites/:site_id/categories(.:format)                                admin/cms/categories#create
           new_admin_cms_site_category GET      /great/sites/:site_id/categories/new(.:format)                            admin/cms/categories#new
          edit_admin_cms_site_category GET      /great/sites/:site_id/categories/:id/edit(.:format)                       admin/cms/categories#edit
               admin_cms_site_category PATCH    /great/sites/:site_id/categories/:id(.:format)                            admin/cms/categories#update
                                       PUT      /great/sites/:site_id/categories/:id(.:format)                            admin/cms/categories#update
                                       DELETE   /great/sites/:site_id/categories/:id(.:format)                            admin/cms/categories#destroy
                       admin_cms_sites GET      /great/sites(.:format)                                                    admin/cms/sites#index
                                       POST     /great/sites(.:format)                                                    admin/cms/sites#create
                    new_admin_cms_site GET      /great/sites/new(.:format)                                                admin/cms/sites#new
                   edit_admin_cms_site GET      /great/sites/:id/edit(.:format)                                           admin/cms/sites#edit
                        admin_cms_site PATCH    /great/sites/:id(.:format)                                                admin/cms/sites#update
                                       PUT      /great/sites/:id(.:format)                                                admin/cms/sites#update
                                       DELETE   /great/sites/:id(.:format)                                                admin/cms/sites#destroy

How ever when I run the route http://localhost:3000/cms , I get an error No route matches in rails 4. And I see no routes of CMS in the browser(as shown by rails 4) but only my existing application routes.

Any help will be appreciated. Thanks

Routes file:

SM::Application.routes.draw do

  comfy_route :cms_admin, :path => '/cms'


  resources :payment_notifications

  get "bookings/create_booking"
  get "bookings/show_rooms"
  post "bookings/comments"  
  post "bookings/check_for_single_sex" 
  get "bookings/convert_to_single_sex" 
  post '/main/payment_values', :controller=>'main', :action => 'payment_values'
  post 'main/update_booking'
  post 'main/date_error'
  get 'bookings/signup'
  post "main/update_nights"

  namespace :admin do 
    resources :periods do
      collection do
        post :not_applicable
      end
    end
    resources :beds do 
      collection do
        post :bed_config
        post :set_peak_prices        
      end
    end
    resources :users do
      collection do
        get :customers
        get :login
      end
      member do
        post :make_admin
      end
    end
    resources :alerts, :except =>[:update, :show, :edit] do 
      collection do
        post :routine_check
        post :seen
      end
    end

    resources :rooms do
      collection do
        get :add_facility
        get :create_facility
        get :available
        get :update_facility
        get :change_room
        post :new_room_name
      end
      member do
        get :details        
        get :edit_facility
        get :change
      end
    end
    get '/calendar/index' => 'calendar#index', :as => :calendar
    get 'bookings/index'
    get 'bookings/create_room'
    get 'bookings/new_room'
    get '/bookings/:guest_id/guest_info/:booking_id', to: 'bookings#guest_info'
    get '/bookings/add_notes'
    get '/bookings/search_booking'
    get '/search', to: 'calendar#search'
    post '/tomorrow', to: 'calendar#tomorrow'
    get '/home', to: 'bookings#home'
  end  

  resources :videos do
    member do
      post :add_comment
    end     
    new do
       post :upload
       get  :save_video
     end
  end

  get "videos/:id/add_comment", :to => "videos#add_comment"
  get "cart/payment"
  get "cart/paid"

  devise_for :users, :controllers => { :confirmations => "confirmations", :omniauth_callbacks => "authentications", :registrations => 'registrations'}
  resources :users, :only =>[:index] do
    member do
      get :dashboard
      get :before_confirmation
    end
  end

  get "main/home_page"

  root :to => 'main#home_page'

  # Make sure this routeset is defined last  
  comfy_route :cms, :path => '/', :sitemap => false

end

回答1:

The docs say this:

"Take a look at routes.rb and make sure that the content serving route appears LAST:"

comfy_route :cms_admin, :path => '/admin'
comfy_route :cms, :path => '/', :sitemap => false

I'am quoting, I'm guessing the problem is where you put

comfy_route :cms_admin, :path => '/admin'


回答2:

According to your code when asking your question, you never defined a :cms route - you only defined :cms_admin twice.

You need this as your last route:

Make sure this routeset is defined last

comfy_route :cms, :path => '/', :sitemap => false

...you also defined this route at the very top of your routes.rb file, which probably should be set second-to-last (or at least, somewhere less high-profile).

comfy_route :cms_admin, :path => '/cms'



回答3:

Your missing comfy_route :cms_admin, :path => '/admin' place it right above

  # Make sure this routeset is defined last  
  comfy_route :cms, :path => '/', :sitemap => false