Ruby on rails 如何防止错误重定向到登录和设计?

Ruby on rails 如何防止错误重定向到登录和设计?,ruby-on-rails,redirect,login,devise,Ruby On Rails,Redirect,Login,Devise,嗨,伙计们,这可能很简单,但我在谷歌的任何地方都找不到答案。 我的Rails应用程序上有一个欢迎页面,当您使用Desive登录时,我希望将用户从该页面直接重定向到posts页面,这与我使用的代码配合良好。唯一的问题是,一旦你登录,我就无法再次访问该页面,因为它显然仍在重定向。是否有人知道在登录时是否有重定向的方法,但如果可能,仍然允许您返回欢迎页面 class WelcomeController < ApplicationController def index if user

嗨,伙计们,这可能很简单,但我在谷歌的任何地方都找不到答案。 我的Rails应用程序上有一个欢迎页面,当您使用Desive登录时,我希望将用户从该页面直接重定向到posts页面,这与我使用的代码配合良好。唯一的问题是,一旦你登录,我就无法再次访问该页面,因为它显然仍在重定向。是否有人知道在登录时是否有重定向的方法,但如果可能,仍然允许您返回欢迎页面

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

class PostsController < ApplicationController
  before_filter :authenticate_user!

  # GET /statuses
  # GET /statuses.json
  def index
    @posts = Post.order('id DESC').paginate(:per_page => 5,:page => params[:page])

    respond_to do |format|
      format.html # index.html.erb
      format.json { render json: @posts }
    end
  end
end
class WelcomeController'posts',:action=>'index'
结束
结束
结束
类PostsController<应用程序控制器
过滤前:验证用户身份!
#获取/获取状态
#GET/statuses.json
def索引
@posts=Post.order('id DESC').paginate(:per_page=>5,:page=>params[:page])
回应待办事项|格式|
format.html#index.html.erb
format.json{render json:@posts}
结束
结束
结束
谢谢。

这个装置

before_filter :authenticate_user 
检查用户是否已登录,并应执行您想要的操作。您需要在PostsController中设置此筛选器。请参阅文档:

设备

before_filter :authenticate_user 

检查用户是否已登录,并应执行您想要的操作。您需要在PostsController中设置此筛选器。请参阅文档:

将登录用户重定向到您的
帖子
页面的方式完全错误

Deave有很多很好的文档说明如何做到这一点-

您应该在
应用程序控制器中添加以下内容:

def after_sign_in_path_for(resource)
  stored_location_for(resource) || posts_path
end

将登录用户重定向到您的
Posts
页面是完全错误的

Deave有很多很好的文档说明如何做到这一点-

您应该在
应用程序控制器中添加以下内容:

def after_sign_in_path_for(resource)
  stored_location_for(resource) || posts_path
end

最简单的方法在Desive的文档中描述

只需在application_controller.rb中定义类似的内容

class ApplicationController < ActionController::Base
  def after_sign_in_path_for(resource)
    posts_path
  end
end
class ApplicationController
最简单的方法在Desive的文档中描述

只需在application_controller.rb中定义类似的内容

class ApplicationController < ActionController::Base
  def after_sign_in_path_for(resource)
    posts_path
  end
end
class ApplicationController
你能展示一下你在PostsController#索引中拥有的东西吗?你能展示一下你在PostsController#索引中拥有的东西吗?谢谢,你知道我会在资源中加入什么吗?谢谢你的帮助你想把你的
config/routes.rb
?嗯,没什么:)谢谢,你知道我会投什么作为资源吗?谢谢你的帮助你想把你的
config/routes.rb
?嗯,没什么:)