redirecting back on errors to multi-form pages

Tom, can you post your controller code, it will probably be best to show you by example.

Tom,

Can you please paste the entire controller so I can see how things like @coach are getting populated. And also post the Coach model (I'm assuming there is one). Please use http://pastie.caboo.se/ so I don't have to reformat the code (after getting mangled) :slight_smile:

http://pastie.caboo.se/

Cheers, Nicholas

Hey, no problem, Tom - I thought I had provided a solution before :slight_smile:

Honestly, I wouldn't worry about the performance at this point. I'm not sure what sort of traffic you are expecting, but if it does become a problem you could try implementing a caching mechanism (e.g. memcache) if it does become an issue. For now, go with the before filters and it will save you a lot of headaches.

I must say though, I would really recommend splitting that controller up though. It looks like you are maintaining about 5 different resources/models in the one controller. It would make it a lot easier for you to split them out into five different controllers - each for coach, teams, players etc. I think it would make things a lot easier to maintain.

Is that enough to move you forward?

Tom,

Even though your "composite" view displays different models you can split it into different controllers. Let's use a basic example of a team has_many players. For this example, I would have two controllers, TeamsController and PlayersController. This would allow for individual updates of each of the models. Even though my "show" method for a team has a list of players as well. In my show template, I can all players in that team by doing something like this:

<h1>Team Detail View</h1>

<h2><%= @team.name %></h2>

<%= render :partial => "players/player", :collection => @team.players %>

In this example I am listing all players of a team with a partial in a different directory. This naming convention is nice way to go because in rails 2.0 you will be able to do this:

<%= render :partial => @team.players %>

Finally, if you have the situation that you create a player when you create a team you could do something like this in your TeamsController:

def create @team = Team.new(params[:team]) @player = @team.players.build(params[:player]) if @team.save   redirect team_url(@team) # or simpley redirect @team in rails 2.0 else    render :action => 'new' end end

if you were simply adding a player to an existing team do this in your PlayersController:

def create @team = Team.find(params[:team_id]) @player = @team.players.build(params[:player]) if @player.save   redirect team_url(@team) # or simpley redirect @team in rails 2.0 else    render :action => 'new' end end

If you want a complete example check out Beast (forum written rails) to show you how to divide an application up.

http://svn.techno-weenie.net/projects/beast/trunk/

You may consider doing a little reading on RESTful design. Although you may not want to make it a restful application, it's a great design technique. Basically, there is a one to one mapping of controller to model and you controller is restricted to the following methods: index, show, new, create, edit, update, and destroy. There's always exceptions of course, but its a great pattern to following.

Helpful? Confusing? :slight_smile:

Cheers, Nicholas