嗨,大家這可能是簡單的事情,但我無法在任何地方在Google上找到答案。 我在我的Rails應用程序上有一個歡迎頁面,當您使用設計器登錄時,我想將用戶從該頁面直接重定向到帖子頁面,該頁面與我正在使用的代碼正常工作。唯一的問題是我不能再次訪問該頁面,一旦你登錄,因爲它顯然仍然重定向。有誰知道登錄時是否有重定向的方式,但是如果可能的話,仍然允許你返回到歡迎頁面?如何防止用Devise登錄錯誤的重定向?
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
謝謝。
你可以顯示你在PostsController#index處有什麼嗎? – poseid