Routing error with devise {:controller=>“devise/st

2020-04-17 06:51发布

问题:

I got a problem with devise. Every time I try to call an Url that should be handled by devise (e.g. http://localhost:3000/users/sign_up) I end up with the following error:

No route matches {:controller=>"devise/static", :action=>"about"}

Hopefully somebody can help me!


routes.rb

devise_for :users

get "pages/contact"
get "pages/imprint"
get "pages/about"

root :to => "pages#about"

What I did:

Added gem 'devise' to the gemfile

bundle install 
rails generate devise:install
rails generate devise User
rake db:migrate

rake routes

        new_user_session GET    /users/sign_in(.:format)       {:action=>"new", :controller=>"devise/sessions"}
            user_session POST   /users/sign_in(.:format)       {:action=>"create", :controller=>"devise/sessions"}
    destroy_user_session DELETE /users/sign_out(.:format)      {:action=>"destroy", :controller=>"devise/sessions"}
           user_password POST   /users/password(.:format)      {:action=>"create", :controller=>"devise/passwords"}
       new_user_password GET    /users/password/new(.:format)  {:action=>"new", :controller=>"devise/passwords"}
      edit_user_password GET    /users/password/edit(.:format) {:action=>"edit", :controller=>"devise/passwords"}
                         PUT    /users/password(.:format)      {:action=>"update", :controller=>"devise/passwords"}
cancel_user_registration GET    /users/cancel(.:format)        {:action=>"cancel", :controller=>"devise/registrations"}
       user_registration POST   /users(.:format)               {:action=>"create", :controller=>"devise/registrations"}
   new_user_registration GET    /users/sign_up(.:format)       {:action=>"new", :controller=>"devise/registrations"}
  edit_user_registration GET    /users/edit(.:format)          {:action=>"edit", :controller=>"devise/registrations"}
                         PUT    /users(.:format)               {:action=>"update", :controller=>"devise/registrations"}
                         DELETE /users(.:format)               {:action=>"destroy", :controller=>"devise/registrations"}
           pages_contact GET    /pages/contact(.:format)       {:controller=>"pages", :action=>"contact"}
           pages_imprint GET    /pages/imprint(.:format)       {:controller=>"pages", :action=>"imprint"}
             pages_about GET    /pages/about(.:format)         {:controller=>"pages", :action=>"about"}
                    root        /                              {:controller=>"pages", :action=>"about"}

Rails Version: Rails 3.1.3


PagesController

class PagesController < ApplicationController
  def contact
  end

  def imprint
  end

  def about
  end

end

回答1:

The error for me was fixed when I changed my link_to methods.

In my header I had:

<%= link_to "Info", :controller => :info %>

and when I switched it to:

<%= link_to "Info", "/info" %>

the error was gone!