On 6/15/07, Armitage [email protected] wrote:
You might have expected an instance of ActiveRecord::Base.
The error occured while evaluating nil.create
I believe your thinking that a has_one assocaition has a create method
a has_many. The has_one association works a bit different. Your patient
will have a create_history method instead. You could rewrite this as
@history = History.new # Does nothing You don’t re-assign it.
flash[:notice] = "Added History"
redirect_to :action =>"show", :id => params[:id]
@history = Patient.find( params[:id] ).create_history(
flash[:notice] = “Added History”
redirect_to :action => “show”, :id => params[:id]
This will effectivley give the same functionality as you have.
You may want to add a bit of a rescue clause in the case that the
not found. Or use find_by_id which doesn’t throw an Exception
but will when you call create_history on nil.
Hope that helps