On Wed, Dec 10, 2008 at 8:21 AM, tom hartwell <[EMAIL PROTECTED]>wrote:

>
> I'm not seeing an error, I'd just like to render the errors to the
> user, but retain the nested route in the url.
>
> Using render, I lose the nesting in the url and I'm left with "/player/
> new"
>
> Does that make sense?
>

Yes, and no.  You are posting a 'new' form to /players/new, or
/players/create?

In your 'new' template, you are probably using something that looks like...

  form_for @player...

The form is getting an action to /players/new (new_player_path).

If you want to get a form action to /league/1/players/new, then you need to
tell your form that your resource is nested.  We've done it in a couple of
different ways...

  form_for [EMAIL PROTECTED], @player]
or
  form_for @player, :url => new_league_player_path(@league)

Since you are not seeing an error, that means that you are routing to your
PlayersController via something other than the nested restful route
(/league/1/players/create).  This could be because you also want 'players'
to be non-nested, or it could be because you have your default route still
active (':controller/:action/:id').  If it is the latter, I would suggest
turning off the default route, and see what happens (you'll learn a lot
about routing by doing so, even if you don't permanently remove the default
route).

Hope that helps.

Darren



> On Dec 10, 8:16 am, "Darren Boyd" <[EMAIL PROTECTED]> wrote:
> > What error are you seeing?
> >
> > When you render an action, it doesn't matter that the controller it
> belongs
> > to might be nested.  If you redirect, it does matter that the target
> might
> > be nested (in which case you might "redirect_to [EMAIL PROTECTED], :players,
> :new]".
> > But, when you render, you can just call "render :action => 'new'".
> >
> > Darren
> >
> > On Wed, Dec 10, 2008 at 7:58 AM, tom hartwell <[EMAIL PROTECTED]
> >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