【问题标题】:Rails 3.1 Devise all of a sudden redirecting to wrong pathRails 3.1 突然设计重定向到错误的路径
【发布时间】:2012-02-15 05:27:23
【问题描述】:

我的登录工作正常,但我不知道我在哪里搞砸了。当我登录时,它会重定向我的会话/用户,这是错误的。这是错误:

No route matches [POST] "/sessions/user"

这是我的路线.rb:

 Wal::Application.routes.draw do

 resources :sessions,   :only => [:new, :create, :destroy]



 devise_for :users, :skip => [:sessions]

devise_for :users  do get '/users/sign_out' => 'devise/sessions#destroy' end 

resources :posts do
resources :comments
end
resources :users, :only => [:show]
resources :microsposts, :only => [:create, :destroy]
match '/' => "home#index", :as => :home

match 'home/index', :to => 'home#index'

get "users/show"

root :to => "home#index"
#get "home/index"

 resources :users do
    member do
     get :following, :followers
   end
end

resources :microsposts, :only => [:create, :destroy]
resources :relationships, :only => [:create, :destroy]

应用程序控制器:

  class ApplicationController < ActionController::Base
   protect_from_forgery

  def after_sign_in_path_for(resource)
    current_user # <- Path you want to redirect the user to after signup
    end
  def after_sign_up_path_for(resource)
   current_user
   end

【问题讨论】:

    标签: ruby-on-rails ruby-on-rails-3.1 devise routes


    【解决方案1】:

    试试这样的

    class ApplicationController < ActionController::Base
      def after_sign_in_path_for(resource)
        stored_location_for(resource) || welcome_path
      end
    end
    

    https://github.com/plataformatec/devise/wiki/How-To:-Redirect-to-a-specific-page-on-successful-sign-in-out

    【讨论】:

      【解决方案2】:

      不知道这是否能解决你的问题,但第一行:

      Wal::Application.routes.draw 做

      在您发布的代码中没有相应的“结束”。

      【讨论】:

      • 我仔细检查了,我做了,我只是没有复制它。它位于 cmets 下方的底部
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-07-01
      相关资源
      最近更新 更多