1

使用 Rspec/Device/Cucumber 模板应用程序登录后,我希望用户被重定向到 users#index 我的路由文件

Engage::Application.routes.draw do
  authenticated :user do
    root to: 'users#show'
  end
  root :to => "home#index"
  devise_for :users
  resources :users, only: [:index]
  resources :agendas, only: [:create, :destroy]
end

登录时出现错误

ActiveRecord::RecordNotFound in UsersController#show

Couldn't find User without an ID

我的 users_controller

class UsersController < ApplicationController
  before_filter :authenticate_user!

  def index
    @user = current_user
    @agendas = @user.agendas
  end
end

我尝试添加“@user = User.find(params[:id])”而不是使用 current_user 辅助方法,但我仍然遇到问题

我在视图下的用户文件夹中的显示视图是

<div class="row">
    <div class="span8">
        <% if @user.agendas.any? %>
            <h2>Agendas (<%= @user.agendas.count %>)</h2>
            <ol class="agendas">
                <%= render @agendas %>
            </ol>
        <% end %>
    </div>
</div>
4

1 回答 1

1

要在登录后重定向用户,您是否看到此帮助:

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

于 2012-05-16T15:35:30.827 回答