0

I have a webapplication in Rails 3, where i want users to be able to sign up on the frontpage. The frontpage is controlled by a PagesController and the sign up process is controlled RegistrationController (I use Devise). I have no problem by adding the sign up form on the frontpage, and everything works when you submit the form correctly. I have just render the form as a partial:

<%= render "/users/registrations/form" %>

And in the form i have

<%= simple_form_for(@user, :url => registration_path(@user)) do |f| %>

However if a user try to submit with errors (eg. missing information), will the user be redirected to the standard sign up page. The errors is displayed fine, but i want the user to stay on the frontpage, with the error messages shown there.

So first of all i need to render the frontpage again, when the sign up process fails, and i want error messages to be shown, but i still want the standard sign up page to work like normally. How can i do this the best way, and still keep it DRY?

Hope you can help me

jokklan
  • 3,520
  • 17
  • 37

2 Answers2

1

I think that what you need is to customize the page to be redirected to after a devise log-in failure.

This is answered in this question: Devise redirect after login fail

If you have two different pages with the signup form and you want to differentiate the redirect depending on that you can try to modify the CustomFailure class that is mentioned in the link as follows:

def redirect_url
  if URI(request.referer).path == your_path_for_your_frontpage
    your_path_for_your_frontpage
  else
    your_standard_path
  end
end
Community
  • 1
  • 1
Galen
  • 957
  • 5
  • 16
  • Thanks, but i still wants the normal sign up page to work normally. So i have to test where the sign up form submission request is coming from somehow? – jokklan May 09 '13 at 16:22
  • So have you got two sign up pages so to speak? – Galen May 09 '13 at 16:25
  • @jokklan I have edited the answer just in case you have two sign up pages – Galen May 09 '13 at 16:32
  • Thanks for the answer! This was exactly was i was looking for! However this is something i often come across, and not always with login and sign up. But i guess you could use the same approach in controllers without devise :) – jokklan May 09 '13 at 20:05
0

You can simply take out your "error message div" in a separate partial and just render it in both of them.

Nerve
  • 6,463
  • 4
  • 29
  • 29