Created
February 18, 2012 00:18
-
-
Save juanm55/1856452 to your computer and use it in GitHub Desktop.
something I did to avoid using 2 root_paths in my routes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def home | |
# get 'login', :to => 'devise/sessions#new' in my routes.rb | |
redirect_to 'login' unless current_user #if not logged in, kick him out of here! | |
end |
- regarding the first block: yes Devise does have something similar
class ThingController < ApplicationController
before_filter :authenticate_user!
end
which would enforce authentication for all of the actions in the controller and redirect to the action I tell it to,,, and it can be passed regular, :only and :except
- sorcery ... haven't used it yet,,, just whipped through the docs and the railscasts (ofcourse) and seems pretty simple to use, and the fact that you get to write the controllers and all does make one think a thing or two, and learn in the process,
I'll consider it for a next project! thanks,,, plus it has a "Very active" (at ruby toolbox) development activity too, so I definitely have to check it out
I really like that if I write the controllers and the logic, I know it, and I know what is being done,,,, with Devise all that logic (the code itself) is hidden (guess for security reasons...) - regarding the idioms: THANK YOU so much.... you are completely right in the use of
not
, it is more readable
the single lineif
I have used it,,, simply didn't remember it on place,,,, and I also like the ternary operator (i saw it on js) and I know there is something similar in ruby but haven't looked up the syntax yet
about this same topic, I have been reading the ruby documentation lately and the rails best practices web, but maybe those aren't the places to find this kind of advices/tricks, if you got any resource that can lead me "out of the dark side" I would greatly appreciate those
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Devies (ugh) should actually have a "require_login" action, so you can do this:
At least, sorcery does (which is a better library anyhow).
This will redirect to the action setup by the library, if the user isn't logged in.
I'll also note two ruby idioms that you should use:
As well as the more clear way to write
!
type conditions: