Search code examples
ruby-on-railsrubydoorkeeper

Ruby/Rails - How to write this syntax?


I'm using Doorkeeper and if I modify current_user in any way, like put it in a conditional statement using unless or if, Doorkeeper won't pick it up. Is there a simple way I can keep current_user || and fit the next two lines containing the session store and redirect to work in one line to the right of the double pipe?

resource_owner_authenticator do

  current_user ||

  session[:after_login_redirect_to] = request.fullpath
  redirect_to('/connect')   

end

Solution

  • You can certainly make an expression out of multiple lines of code, simply wrap them in brackets.

    current_user || (session[:after_login_redirect_to] = request.fullpath; redirect_to('/connect'))