I have this line in my votes controller:
before_filter :authenticate
So when I vote while logged out, it should fail this filter.
My authenticate method in my application controller looks like this:
def authenticate
logged_in? ? true : access_denied
end
So it returns access_denied
which looks like this:
def access_denied
redirect_to login_path, :notice => "You must log in to perform this action." and return false
end
Therefore, I should be redirected to my login page, right?
I have this in my routes.rb file:
match '/login' => "sessions#new", :as => "login"
and I have a new
view with a login form that I should be redirected to when I vote and I'm not logged in. I also have this code in the create
method of my votes controller:
if @vote.save
respond_to do |format|
format.html { redirect_to @video }
format.js
end
else
respond_to do |format|
format.html
end
end
But when I vote, I am not redirected, and I get this error message in my logs:
Started GET "/login" for 127.0.0.1 at Thu Mar 24 21:18:08 -0700 2011
Processing by SessionsController#new as JS
Completed in 17ms
ActionView::MissingTemplate (Missing template sessions/new with {:locale=>[:en, :en], :formats=>[:js, "*/*"], :handlers=>[:rhtml, :rxml, :erb, :builder, :rjs]} in view paths "/rubyprograms/dreamstill/app/views"):
Why is this happening, and how can I make this redirect work?