开发者

Rails - Devise - How to Handle Landing Pages Versus App Pages

开发者 https://www.devze.com 2023-01-21 15:53 出处:网络
I have a Rails 3 App. When the use开发者_开发技巧r is not signed in... I want devise to show non-signed in pages: SignIn, register,about us, blog etc...

I have a Rails 3 App.

When the use开发者_开发技巧r is not signed in... I want devise to show non-signed in pages: SignIn, register, about us, blog etc...

When a user is signed in I want it to go to the web app

where do I make this switch and how do I set it up? thanks


This is easy! I just finished a Rails 3 app with devise, so my pain can be your gain. Just include the before_filter at the beginning of the controllers you want to protect. Let's use the example of a Videos controller:

class VideosController < ApplicationController
  before_filter :authenticate_user!

  # all your actions go here: index, new, create, etc #
end

You can also pick and choose what actions in the controller are filtered:

class VideosController < ApplicationController
  before_filter :authenticate_user!, :only => [:edit, :update, :destroy]

  # all your actions go here: index, new, create, etc #
end

Devise gives you the authenticate_user! method, and redirects for you.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号