登录后设计不重定向

devise not redirect after sign in

我是 rails 世界的新人,我需要一点帮助,我 运行 设计 gem 并且工作完美,我只是在登录后遇到了一个小问题,我我没有找到想要的页面,总是重定向到我的索引页面,你们能帮帮我吗?

关于视图:我有用于仪表板和索引的索引文件。

这是我的代码:

routes.rb

Rails.application.routes.draw do
  devise_for :users
  resources :dashboard
  root to: "home#index"

dashboard_controller.rb

class DashboardController < ApplicationController
  before_filter :authenticate_user!

  def index    
  end
end

home_controller.rb

class HomeController < ApplicationController
  def index
    if user_signed_in?
      redirect_to :controller=>'dashboard', :action => 'index'
    end
  end
end

aplication.html.erb

<!DOCTYPE html>
<html>
<head>
  <title>Devise</title>
  <%= stylesheet_link_tag    'application', media: 'all', 'data-turbolinks-track' => true %>
  <%= javascript_include_tag 'application', 'data-turbolinks-track' => true %>
  <%= csrf_meta_tags %>
</head>
<body>
<div id="user_nav">

<% if user_signed_in? %> 
Signed in as <%= current_user.email %>. Not you? 
<%= link_to "Sign out", destroy_user_session_path, :method => :delete %> 
<% else %>
 <%= link_to "Sign up", new_user_registration_path %> or <%= link_to "sign in", new_user_session_path %> 
 <% end %>

</div>

<% flash.each do |name, msg| %>
  <%= content_tag :div, msg, :id => "flash_#{name}" %>
<% end %>



<%= yield %>

</body>
</html>

编辑: 找到了解决方案: 添加 aplication_controller.rb

 def after_sign_in_path_for(resource)
     dashboard_index_path
   end

谢谢你,祝你一切顺利

在您的应用程序控制器中添加以下方法:

  def after_sign_in_path_for(resource)  
     dashboards_path #edited
  end

更多详情请关注以下内容link

编辑

你的应用程序控制器必须是这样的

class ApplicationController < ActionController::Base
   # Prevent CSRF attacks by raising an exception.
   # For APIs, you may want to use :null_session instead.
   protect_from_forgery with: :exception

   def after_sign_in_path_for(resource)
     dashboard_index_path
   end

end

试试这个,

redirect_to url_for(:controller => :dashboard, :action => :index)
class DashboardController < ApplicationController
**end**
before_filter :authenticate_user!

def index    
end

为什么dashboard controller和home controller在before_filter之前有end,请删除并添加到文件末尾。

其次使用redirect_to dashbaord_path代替redirect_to :controller=>'dashboard', :action => 'index'