I tried to find solution by google and here in SO but couldn’t found…
This is the only question. It has only one answer and it’s accepted but doesn’t work for me… Here is my code:
class RegistrationsController < Devise::RegistrationsController
before_filter :authenticate_user!
def new
puts "Method new was called"
super
end
end
When I’m not logged in at localhost:3000/sign_up page is displayed normally and Method new was called is printed. I want controller to redirect me into sign_in page if I’m not already signed in. Of course I can check it in new method and redirect but it’s not a good solution… I’m sure there is a more elegant way. I even tried to use prepend_before_filter :authenticate_user! but it doesn’t work too.
EDIT
I’ve defined routes for this controller in routs.rb
devise_for :users, :controllers => { :sessions => "sessions", :registrations => "registrations" }
Devise::RegistrationsControllerhas require_no_authentication before filter by default.So it’s needed to skip it: