Monday 29 June 2009

So far, so good

It is Mao's journey of a thousand miles, it begins with one step. So far, most problems have been resolved by throwing enough time and hard work at them.
The next problem - a recalcitrant radio button that refuses to pick up its value:


<%= f.label :verhorcut, "horizontal" %> <%= f.radio_button :verhorcut, 0 %>
<%= f.label :verhorcut, "vertical" %> <%= f.radio_button :verhorcut, 1 %>



there is a field called verhorcut - it is returning the correct value, but so far seem unable to pick up a value for it. In the schema it is a boolean so have tried "0", 0 and "false" but nothing so far.
Keep plodding away.

Next on the agenda - some proper unit testing.

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.

Learning a new language

One of the things I hate most about this is how slooowwwwwwww it is. You know you are going to get there, but boy does it take time.
RoR is proving to be a tricky beast. All that is great about it is also all that is bad. The abstraction is great when it works, but when it doesn't - grrrr.
Having cut my teeth on PHP and writing SQL statements it is so frustrating knowing that you know how to do what you want, but getting the RoR framework to do your bidding is the devil's own business.
Still we will get there.

Currently still grasping at associations. Everytime I think I have got them grasped, they slip through your fingers.
Grappling with a "
NameError in Stored filesController#index
uninitialized constant StoredFilesController::StoredFiles"

But we'll get there. Have to say loving the console - being able to try stuff out before you buy - lovely.