Instance variable stop working in after_inactive_sign_up_path_for stop from 2.1

70 views
Skip to first unread message

ApuX

unread,
May 26, 2012, 2:59:54 PM5/26/12
to plataforma...@googlegroups.com
Hi.

In after_inactive_sign_up_path_for for method, I used to set some instance variables. Example

def after_inactive_sign_up_path_for(resource)
  @email = resource.email
  '/home/some_view.html'
end

And then, I could use te variable in the view

#home/some_view.html

<%= "Registered as #{@email}" %>

It worked fine in 2.0, but not in 2.1. Is this a bug, or is there another way to do that?

Do I need to provide more information or code?

ApuX

unread,
Jun 3, 2012, 7:54:05 PM6/3/12
to plataforma...@googlegroups.com
By the way, it is not possible to access the email field directly from resource in the view. Example
<%= "Registered as #{resource.email}" %>

Carlos Antonio da Silva

unread,
Jun 3, 2012, 8:30:54 PM6/3/12
to plataforma...@googlegroups.com
I don't quite understand what you're trying to achieve here. This after_inactive_sign_up_path_for is supposed to be called for a redirect, where instance variables would never work because it's a completely different controller instance.

About `resource` being accessible, yes it should be in views from devise controllers, not everywhere. In other views you get helpers like current_user (considering :user is your scope).

-- 
At.
Carlos Antonio

ApuX

unread,
Jun 3, 2012, 9:18:15 PM6/3/12
to plataforma...@googlegroups.com
Thanks for answer.


I don't quite understand what you're trying to achieve here. This after_inactive_sign_up_path_for is supposed to be called for a redirect, where instance variables would never work because it's a completely different controller instance.

I want to show a 'thanks for subscribe' page, and therefore I need some information from the resource, for example, the username, email an so on. I was able to do that on devise 2.0 but not in 2.1.
Is there another way to get the same behavior? What do you recommend for this?

About `resource` being accessible, yes it should be in views from devise controllers, not everywhere. In other views you get helpers like current_user (considering :user is your scope).

Yes. I actually can't access 'resource' in that page because the user is not logged in, but it is not important, I just commented it to up the post.
 

Carlos Antonio da Silva

unread,
Jun 4, 2012, 7:46:37 AM6/4/12
to plataforma...@googlegroups.com
I can see two possibilities: 

1. Customize the create action from RegistrationsController, particularly this part: https://github.com/plataformatec/devise/blob/master/app/controllers/devise/registrations_controller.rb#L21-L23. You'd change that to render the view you want and you'll have access to `resource`.

2. Save the info you want in the session, let the redirect happen to that particular path you've set up. In that action you grab the info back from the session and display the "thank you" page with that info (don't forget to cleanup the session).

Option 2 might be better to avoid users doing refreshes and re-sending the registration form to the server, imho.

-- 
At.
Carlos Antonio

ApuX

unread,
Jun 4, 2012, 7:41:58 PM6/4/12
to plataforma...@googlegroups.com
Ok. Thank you very much.
Reply all
Reply to author
Forward
0 new messages