27.02.2013 Views

Rails%203%20In%20Action

Rails%203%20In%20Action

Rails%203%20In%20Action

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Fixing what you broke<br />

actions in it, checking if users are authenticated. If they aren’t, they’re redirected to<br />

the sign-in page.<br />

You can see all of this in action if you start your server using rails server and<br />

attempt to sign up. Rather than being properly shown the “You have signed up successfully”<br />

message, you’ll see the Sign In page, as shown in figure 8.3.<br />

The configuration to send users to the root_path after sign-up is in Devise’s<br />

Devise::RegistrationsController 1 and is defined in a method called after<br />

_inactive_sign_up_path_for:<br />

# The path used after sign up for inactive accounts.<br />

➥You need to overwrite<br />

# this method in your own RegistrationsController.<br />

def after_inactive_sign_up_path_for(resource)<br />

root_path<br />

end<br />

As you can see, this method is hardcoded to return root_path. The comment above this<br />

method suggests that you override the method in your own RegistrationsController.<br />

It means you must create a new controller called RegistrationsController 2 and,<br />

inside this controller, override the after_inactive_sign_up_path_for method. To<br />

give this controller the same functionality as Devise’s Devise::Registrations<br />

Controller, you need to inherit from that controller. Finally, you can no longer redirect<br />

to root_path, so you generate a new part of your application to present new users with<br />

a message telling them they must confirm their account.<br />

Figure 8.3 Sign-in page<br />

1 The Devise::RegistrationsController can be found at https://github.com/plataformatec/devise/<br />

blob/v1.4.2/app/controllers/devise/registrations_controller.rb#L93-95.<br />

2 The controller could be called anything: it just needs a name so you can point Devise at it later.<br />

179

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!