I suppose my initial description was vague, I'll include some code to
give you guys a better idea
So in my new player view I didn't know about the form_for(@parent,
@obj...) I'll try that out. Instead I just had a hidden field in my
new player form for the league like so:
<% form_for :player, :url => { :action => 'create' }, :html =>
{ :class => 'myform' } do |f| %>
<% if @league %>
<%= hidden_field :league, :id %>
<% end %>
<%= f.error_messages %>
<%= f.label :first_name, "First Name", :class => "left" %>
<%= f.text_field :first_name %>
Darren, you are correct in that I would like the player routes to be
both nested and non-nested. This does seem to complicate the
controller a bit, but perhaps my first hack at the Player#create
method can be refactored. Here is the gist of the create
def create
@player = Player.new(params[:player])
respond_to do |format|
if @player.save
flash[:notice] = 'You have successfully created your account.'
if params[:league] && params[:league][:id]
format.html { redirect_to(new_league_registration_path(params
[:league][:id])) }
else
format.html { redirect_to(player_path(@player)) }
end
format.xml { render :xml => @player, :status
=> :created, :location => @player }
else
format.html {
if params[:league][:id]
redirect_to new_league_player_path(params[:league][:id])
#render :action => 'new', :prefix => "leagues/#{params
[:league][:id]}"
else
render :action => 'new'
end
}
format.xml { render :xml => @player.errors, :status
=> :unprocessable_entity }
end
end
end
If the player is not saved successfully, I would like to render player/
new, either nested if it is a player that is registering for a league
(via the nested route) at the same time they are creating their own
player object, or non-nested if they are just registering on the site.
I am using authlogic for users and players are a user subclass.
I would like to render :action => 'new', but the render method doesn't
seem to handle rendering a page that is located in a nested route, b/c
I end up on /players/new instead of /leagues/1/players/new.
Scott, currently I'm using authlogic's default validations which are
built into the gem and will expound on those once I get the basic flow
of the pages going.
If I redirect_to, I loose the player object...form fields are blank,
and I loose the objects error_messages (password conf doesn't match,
for example), so redirect_to is def not the method I want...or so I
think :)
Thanks again everyone for the timely responses,
Tom
--~--~---------~--~----~------------~-------~--~----~
SD Ruby mailing list
[email protected]
http://groups.google.com/group/sdruby
-~----------~----~----~----~------~----~------~--~---