# Persist the same url even if validation fails

**URL:** <https://www.ruby-forum.com/t/persist-the-same-url-even-if-validation-fails/186847>\
**Category:** Rails\
**Created:** [April 13, 2010, 10:07am UTC](https://www.ruby-forum.com/t/persist-the-same-url-even-if-validation-fails/186847 "2010-04-13T10:07:37Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![tom-mac](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/bc8723/32.png) [@tom-mac](https://www.ruby-forum.com/u/tom-mac)\
**Post date:** [April 13, 2010, 10:07am UTC](https://www.ruby-forum.com/t/persist-the-same-url-even-if-validation-fails/186847/1 "2010-04-13T10:07:37Z")

</div>

Hi  
I have routes defined like  
map.resources :staff, :member =\> {:registration\_completion =\> :put}  
map.staff\_registration ‘/staff\_registration/:code’, :controller =\>  
‘staff’, :action =\> ‘registration’

And I have controller actions like

def registration  
@user = User.find\_by\_perishable\_token!(params[:code])  
[@staff](https://www.ruby-forum.com/groups/staff) = @user.staff  
render :action =\> :registration, :layout =\> ‘registration’  
end

And this render the file registration which is edit form The form is

\<% form\_for @user, :url =\> staff\_registration\_completion\_url([@staff](https://www.ruby-forum.com/groups/staff)),  
:html =\> {:method =\> :put} do |f| %\>

* * *

\<%end%\>

And upon submission this goes to action  
def registration\_completion  
[@staff](https://www.ruby-forum.com/groups/staff) = Staff.find(params[:id])  
@user = @staff.user  
if @user.update\_attributes(params[:user])  
redirect\_to login\_url  
else  
flash.now[:error] = @user.errors.full\_messages.join(“  
”)  
render :action =\> :registration,:layout =\>  
‘company\_registration’  
end  
end

```
 And my problem is before submitting the form the url is like

```

[http://localhost:3000/registration/FFhJhsVz](http://localhost:3000/registration/FFhJhsVz)

```
 But if in the registration_completion action if it capture any

```

error sure it will render else part That is registartyion action again  
.Which is what I expect. But now the url is  
[http://localhost:3000/registration\_completion/2/edit](http://localhost:3000/registration_completion/2/edit)

```
      My question is how can I make the url even if the update fails

```

to  
[http://localhost:3000/registration/FFhJhsVz](http://localhost:3000/registration/FFhJhsVz) .What changes should I  
made to routes? Please help

Thanks  
Tom

---

<div class="post-metadata">

**Author:** ![tom-mac](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/bc8723/32.png) [@tom-mac](https://www.ruby-forum.com/u/tom-mac)\
**Post date:** [April 13, 2010, 10:40am UTC](https://www.ruby-forum.com/t/persist-the-same-url-even-if-validation-fails/186847/2 "2010-04-13T10:40:24Z")

</div>

Hi  
I could solve it by modifying routes like

map.connect ‘/staff\_registration/:code’, :controller =\> :staff,  
:action =\> :registration\_completion,:conditions =\> { :method =\> :put }  
map.staff\_registration ‘/staff\_registration/:code’, :controller =\>  
‘staff’, :action =\> ‘registration’

## And modified action registration\_completion like def registration\_completion @user = User.find\_by\_perishable\_token!(params[:code]) [@staff](https://www.ruby-forum.com/groups/staff) = @user.staff

-----------etc  
end

## And also form\_for like \<% form\_for @user, :url =\> staff\_registration\_url(:code =\> params[:code]), :html =\> {:method =\> :put} do |f| %\>

```
   This problem was there in my mind for months. Now it is solved. 

```

Posting it for whom search with similar problem

Thanks  
Tom
