in a Rubyonrails application i want only logged in users to enterinto the inner pages?
how can i redirect the direct entered urls to index page?
in php if(!isset($_SESSION[id]) { header(“location:index.php”) }, how this can be implemented in ruby on rails
here goes
In application_controller.rb:
Putting this code in application_controller will make it available to all your controllers.
Then you can make use of this method in any of the controllers that require it, for eg
If you need to confirm that users are logged in for the show action, then
should work, as this will confirm that users accessing this show url have logged in.
For more info checkout this link to rails guides on filters. There could be more efficient ways of achieving this as well.
However, i would suggest using a gem like Cancan (Github) as i have used this in many apps and works well. The code presented above is basic and there are many better and advanced ways to handle this but it should do the job.Hope it helps.