0

我为设计操作添加了自定义路线。当我尝试转到 /profile/edit 或 /login 或 /logout 时,这不起作用这是 rake 路由:

saasbook@saasbook:~/Documents/ronde$ rake routes
        static_about GET      /static/about(.:format)                static#about
         static_tour GET      /static/tour(.:format)                 static#tour
         static_home GET      /static/home(.:format)                 static#home
 static_terms_of_use GET      /static/terms_of_use(.:format)         static#terms_of_use
      static_contact GET      /static/contact(.:format)              static#contact
       users_profile GET      /users/profile(.:format)               registrations#edit
               login GET      /login(.:format)                       devise/sessions#new
              logout GET      /logout(.:format)                      devise/sessions#destroy
            register GET      /register(.:format)                    devise/registrations#new
        profile_edit GET      /profile/edit(.:format)                devise/registrations#edit
    new_user_session GET      /users/sign_in(.:format)               devise/sessions#new
        user_session POST     /users/sign_in(.:format)               devise/sessions#create
destroy_user_session GET      /users/sign_out(.:format)              devise/sessions#destroy
user_omniauth_authorize GET|POST /users/auth/:provider(.:format)        omniauth_callbacks#passthru {:provider=>/google|facebook/}
user_omniauth_callback GET|POST /users/auth/:action/callback(.:format) omniauth_callbacks#(?-mix:google|facebook)
       user_password POST     /users/password(.:format)              devise/passwords#create
   new_user_password GET      /users/password/new(.:format)          devise/passwords#new
  edit_user_password GET      /users/password/edit(.:format)         devise/passwords#edit
                     PUT      /users/password(.:format)              devise/passwords#update
cancel_user_registration GET      /users/cancel(.:format)                devise/registrations#cancel
   user_registration POST     /users(.:format)                       devise/registrations#create
 new_user_registration GET      /users/sign_up(.:format)               devise/registrations#new
edit_user_registration GET      /users/edit(.:format)                  devise/registrations#edit
                     PUT      /users(.:format)                       devise/registrations#update
                     DELETE   /users(.:format)                       devise/registrations#destroy
                root          /                                      static#home

这是我的 routes.rb 文件,我在其中添加了具有相同控制器操作的新路由以进行设计:

Ronde::Application.routes.draw do

get "static/about"
get "static/tour"
get "static/home"
get "static/terms_of_use"
get "static/contact"
get "/user/profile", :to => 'registrations#edit'
get "/login", :to => "devise/sessions#new" # Add a custom sign in route for user sign in
get "/logout", :to => "devise/sessions#destroy" # Add a custom sing out route for user sign out
get "/register", :to => "devise/registrations#new" # Add a Custom Route for Registrations
get "profile/edit", :to => "devise/registrations#edit"

devise_for :users, :controllers => { :omniauth_callbacks =>  "omniauth_callbacks" }


root to: 'static#home'
end

# :path_names => {:edit => "profile/edit", :sign_in => "login", :sign_out => "logout",     :sign_up => "register" }

然后页面说,应该路由到设计控制器:

Routing Error

No route matches [GET] "/profile/edit"
Try running rake routes for more information on available routes.
4

1 回答 1

0

我不知道这是否正确,但我认为你不能那样做,因为 Devise 没有任何控制器。请检查这个问题这个

我通常做的是为 Devise 制作另一个控制器,或者像users_controller它自己的视图一样的普通控制器。并routes.rb像这样注册:

devise_for :users

scope "/admin" do
  resources :users
end

然后当我需要打开它时,我打电话给localhost:3000/admin/users

但是,如果有任何问题,或者我的做法是错误的,请纠正我。希望能有所帮助。

于 2013-10-30T06:51:18.510 回答