# Quick question with restful\_authentication and validations

**URL:** <https://www.ruby-forum.com/t/quick-question-with-restful-authentication-and-validations/134662>\
**Category:** Rails\
**Created:** [April 13, 2008, 4:59pm UTC](https://www.ruby-forum.com/t/quick-question-with-restful-authentication-and-validations/134662 "2008-04-13T16:59:13Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [April 13, 2008, 4:59pm UTC](https://www.ruby-forum.com/t/quick-question-with-restful-authentication-and-validations/134662/1 "2008-04-13T16:59:13Z")

</div>

Hi everyone,

I’m using restful\_authentication for my app - using Rails 2.0.2. I  
have things configured properly, and I’m using the “shortcut” named  
route of signup in my routes.rb like so:

map.signup “/signup”, :controller =\> “users”, :action =\> “new”

My /views/users/new.html.erb file has the form set up like this  
(unchanged from restful\_authentication):

\<% form\_for :user, :url =\> users\_path do |f| -%\>

Username  
 \<%= f.text\_field :login %\> \<%= error\_message\_on :user, :login, "↑ Username", " is required"%\>

Email  
 \<%= f.text\_field :email %\> \<%= error\_message\_on :user, :email, "A valid email address", " is required" -%\>

Password  
 \<%= f.password\_field :password %\>  
 \<%= error\_message\_on :user, :password, "A password is required" -%\>

Confirm Password  
 \<%= f.password\_field :password\_confirmation %\>  
 \<%= error\_message\_on :user, :password\_confirmation, "Passwords must match" -%\>

\<%= submit\_tag 'Sign up' %\>

\<% end -%\>
* * *

Everything works, but there’s a stylistic problem - To go to the  
signup page, the user goes to [http://myapp/signup](http://myapp/signup). If validation  
fails, though, when the page reloads to show validation errors, the  
address bar reads [http://myapp/users](http://myapp/users), and if the user accidently hits  
Return/Enter it will give an error because there is no index action in  
the UsersController (nor do I want one - UsersController is _only_  
going to deal with signing up new users). Is there any way to make it  
stay as [http://myapp/signup](http://myapp/signup)? I’ve tried changing the :url parameter  
of the form to signup\_url, but this doesn’t work because it just  
reloads the form without actually invoking the create method (which  
makes sense because the signup route points to the new action, not to  
create).

I’ve done a Google search but no avail. I’m still a little new to  
Rails and, honestly, to RESTful concepts as well but I am trying to  
learn. Any help solving this problem would be appreciated.

Also, does anyone know how to override the error\_message\_on method so  
it won’t return a DIV tag? I want my validations to appear next to  
the textbox in question, not below them. Changing the CSS property of  
the formError DIV to display: inline doesn’t do anything - the new DIV  
is still placed below the offending textbox. This isn’t really a big  
deal, as I can modify the layout to accommodate it. The address bar  
issue is a bigger problem because it’s user-facing and confusing.

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [April 14, 2008, 4:00pm UTC](https://www.ruby-forum.com/t/quick-question-with-restful-authentication-and-validations/134662/2 "2008-04-14T16:00:16Z")

</div>

Wayne M wrote:

> makes sense because the signup route points to the new action, not to  
> create).

## The URLs and process flow in your web app are handled by the routes.rb file and the controllers. In this case, you have the route defined, you just need to make sure the controller is using it consistently. I have a basic restful\_authentication web app and this is the “create” method from my users\_controller.rb file:

## def create cookies.delete :auth\_token @user = User.new(params[:user]) @user.register! if @user.valid? if @user.errors.empty? self.current\_user = @user flash[:notice] = “Thanks for signing up!” redirect\_back\_or\_default(’/’) else redirect\_to signup\_path; end end

In short:

1. Attempt to create new user after checking that form data is valid.
2. If there are no errors, create the user.
3. Otherwise, redirect\_to signup\_path

“signup\_path” is defined by the rails framework when you set up the  
“/signup” shortcut in your routes.rb file.

- Aaron
