Persist the same url even if validation fails

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 = @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),
:html => {:method => :put} do |f| %>


<%end%>

And upon submission this goes to action
def registration_completion
@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

 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

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

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

Thanks
Tom

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 = @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

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs