1

I simply can do a

if not user_signed_in? 
      redirect_to new_user_session_path

for each action need authentication. I imagine there should be more elegant way to do so.

Thanks

4

1 回答 1

1

Add before_filter :authenticate_user! in the controllers that should have user authentication.

Reference: https://github.com/plataformatec/devise#controller-filters-and-helpers

If not all actions in the controller require user authentication, implement a custom before filter as explained in https://stackoverflow.com/a/6034498/429758

If the whole application needs user authentication, then the above line belongs in app/controllers/application_controller.rb file.

于 2013-02-18T04:55:09.037 回答