Suppose my website URL is http://localhost:3000,
But when user manually type http://localhost:3000/orders, he should be redirected to root_path or some other path because this url is only valid after session is created.
and I am getting
NoMethodError in OrdersController#index
To make sure user will be redirected to root url you have to use some
before_action
(before_filter
in Rails 3) to your controller.
For example if you're using Device gem for authentication you have to add to your controller:
before_action :authenticate_user!
(more details...)
If you have your own authentication system you have to implement manually something like device's authenticate_user!
method to set current_user.
If I correctly understood your issue you should get the idea.