Tom,

I'm not sure what you mean by your wanting to "retain the errors" but if you are not using validation to check for the errors in information submitted, I highly recommend it.

As a relative noob, I was doing some error checking in a controller and running into the problem of the how to get their input back into the form. Once I moved all such checking into validation I had no more problems because Rails handled just about everything, and I have nested routing much like yours.

For example, in a RESTful controller, you might have a create method that looks the following:

def create
  @signup = Signup.new(params[:signup])
  if @signup.valid?
     @quiz.save
     flash[:notice] = 'Signup successful'
     redirect_to  somewhere_path
  else
     render :action ="" "edit" # if you have a view for editing a signup, maybe "new" would work
        # Rails or your custom validation routine will insert a div with class errorExplanation
  end
end

If you want to retain the erroneous information, perhaps you could get it from the errors object before rendering the view where the user tries again.

And if I've completely misconstrued everything, just ignore this, I'm still learning (but having so much fun!).

Scott 


At 07:58 AM 12/10/2008, you wrote:

Hey everyone, I had a question about the render method inside a Rails
controller.  Looking at the source of the render method ( http://
api.rubyonrails.org/classes/ActionController/Base.html#M000512
) it
seems like it does not process a path prefix or nested route.  An
example that I'm banging my head against follows:

1) Player signs up for a league via a nested url "/leagues/1/players/
new"
2) There is an error in the information submitted
3) In my controller I would like to retain the errors so a redirect_to
cannot be used, but render doesn't seem to do the trick, either.
Something like the following (if it were supported) would work:

render :action ="" 'new', :prefix => "leagues/#{params[:league_id]}"

Perhaps I'm missing something and there is a way to do it.  Thanks,
Tom

--~--~---------~--~----~------------~-------~--~----~
SD Ruby mailing list
[email protected]
http://groups.google.com/group/sdruby
-~----------~----~----~----~------~----~------~--~---

Reply via email to