Tuesday 23 June 2009

Everything comes to he who waits

Problem solved. It was behaving very oddly - as if the class didn't really exist properly. Rebuilt the controller and now all works. Hurrah.

Next problem.
Have three classes:
class StoredFile < ActiveRecord::Base
belongs_to :job_store_path
belongs_to :job_set_up
accepts_nested_attributes_for :job_store_path, :allow_destroy => true

class JobSetUp < ActiveRecord::Base
has_many :stored_files
has_many :job_store_paths, :through => :stored_files
accepts_nested_attributes_for :stored_files, :allow_destroy => true
accepts_nested_attributes_for :job_store_paths, :allow_destroy => true

class JobStorePath < ActiveRecord::Base
has_many :stored_files
has_many :job_set_ups, :through => :stored_files

The idea is to generate suggested path names for files, but then store the actual path name so that should the structure change, the old files are not going to be lost.
This works fine:
<% @job_set_up.stored_files.each do |stored_file| %>
<%= content_tag(:strong, stored_file.job_store_path_id) %>
<%=stored_file.address %>

<% end %>

But what I really want is:
stored_file.job_store_path.name - but if I do this I get:

NoMethodError in Job_set_ups#show

Showing app/views/job_set_ups/show.html.erb where line #11 raised:

You have a nil object when you didn't expect it!
The error occurred while evaluating nil.name


Ho hum.

No comments:

Post a Comment