getting errors and params back to view

I asked this question here:Redirecting back on errors to multi-form pages - Rails - Ruby-Forum but let me try to put it more succinctly.

Below I show a controller action controller meant to save a new item with its association. The page with the orignating form has displays of other instances of the same model type and parent and associations thereof.

If a user enters information for a fposition with a field entry that fails validation, I can't get the error messages and information back to the view.

If I just render the view, the view seems to be missing all the instance variables it needs. (instance variables only last one action I guess). If I redirect to the view action that initially rendered the view, that action creates a new object without the errors and partially completed data from the first attempt.

def create_fposition     @fposition =[:fposition])     @formation = session[:formation]     @coach = session[:coach] #need help here      if @fposition #! Help here please...need a condition !!!

@fposition will not be nil because it an Fposition object.(a new Fposition object can be nil?) maybe you want to do @fposition.valid?


Can you use a before_filter to setup the common instance variables? This way you can use render to display validation errors without issues of the select boxes.

For example:

before_filter :setup :only => [:formations_fpositions, :create_fposition]

def setup @formation = session[:formation] @formation_fpositions = @formation.fpositions end

HTH, Nicholas