Ruby on Rails Friday, May 2, 2014

Hello Alfredo,

Could you please provide where and how the current_user is being defined. Are you using an gem for registration/authentication or this is manually defined code?

Also please share the content of controller which contains the action 'home'(for home_path) ?

Well, my guess is that either devise(https://github.com/plataformatec/devise/) or sorcery(https://github.com/NoamB/sorcery/) is being used. If this is the case, it is recommended to use following methods provided by these gems.

1. devise - :authenticate_user! - https://github.com/plataformatec/devise#controller-filters-and-helpers

2. sorcery - :require_login - https://github.com/NoamB/sorcery#api-summary

Thanks,
Lauree


On Friday, May 2, 2014 3:49:02 PM UTC+5:30, Alfredo Barrero wrote:
Good afternoon all,

I'm trying to restrict the access to the application to paths like "localhost:3000/users/1" without a previus login. To do that I have create this function:

'session_controller.rb'
  before_action :authorize

  def authorize
    if current_user.nil?
      redirect_to home_path
    else
      redirect_to user_path(current_user.id)
    end
  en
d

When the 'current_user' is nil it entryes to an infinite loop. What I have to do to solve this?.


Thanks & Best regards.


Alfredo.

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/48d8c488-642c-4df4-aa0a-74605c3bbc6e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment