It has been slow progress so far. So I have decided to take an alternate approach and work through the Depot Application tutorial in Agile Web Development with Rails, Third Edition .
I have been able to make some progress on building the admin interface for Website Poll. It took me quite some time to understand the associations functionality.
The first part in associations of setting it up in the models is straight forward enough. For example :-
class Rating < ActiveRecord::Base
belongs_to :website
end
class Website < ActiveRecord::Base
has_many :ratings
end
The area where I had problems was in using the associations setup. However I was “over thinking” it and in the end it was really simple. For example in the view (Index.html.erb) :-
<% for rating in @ratings %>
<tr>
<td><%=h rating.website.url %></td>
This is the secret to it where it has “rating.website.url” and because of the associations being set it knows that “url” is associated with the website model. It almost seems too simple to work but it does.
Posted by Norman 