Topic: Transaction

On my project I have something like this:

class Assessment< ActiveRecord::Base
  has_one :field_test
  has_one :cardio_test
  belongs_to :trainer
  belongs_to :person

My Assessment controller:

class AvaliacaosController < ApplicationController
  def new
    @people= People.all
    @assessment =

  def create
    @person = People.find(params[:id])
    @trainer= Trainer.find(session[:avaliador_id]) if session[:avaliador_id]
    @assessment = =>, :trainer_id =>
    if (!)
      redirect_to avaliacao_path(, :notice => "Assessment saved"
      render ("new")

The problem is that the links to the :field_test and :cardio_test (and several others) AND the results of the calculations to those forms are on my Assessment Show page. Thats a bad thing because the user can create an Assessment and leave the page leaving the tests (field, cardio etc) nil.
I manage to prevent some problems using if statments on my views to check if things are nil. How can I improve this? Other ways I tried didn't worked because when I needed to assign the Foreing Keys the Assessment was not saved to the database.

Re: Transaction

That's a little confusing

First  if you are showing your assessment controller,  then this:

def create
  @person = People.find(params[:id])

is odd to say the least.

I think you may need to straighten things out,  and read up a bit on nested things in rails.

What are the over all relationships between all the models?

If it makes sense you may want to define nested resources … -resources

Joe got a job, on the day shift, at the Utility Muffin Research Kitchen, arrogantly twisting the sterile canvas snout of a fully charged icing anointment utensil.

Re: Transaction

The @person on assessment controller is to assign the person_id FK on assessment. I belive my FKs are all messed up, things inverted (has_one where it should be belongs_to)
If you have some time to check the source of my project is here
Yes... there is alot of useless code I was making tests on that project smile

The nested resources make sense, but im failing to see how that can help me other than giving me a more descriptive url

Last edited by CassioGodinho (2011-11-04 17:37:25)