John I. wrote:
from the rails recipes i have a has_many through “working”.
I can list a user and what magazines he subscribes to. but I can’t
seem to figure out how to get the other attributes from subscriptions.
@readers = Reader.find(1)
<%= reader.last_renewed_on %>
<%= reader.subscription.last_renewed_on %>
<%= subscription.last_renewed_on %>
- <%= readers.name %>
<% @readers.magazine.each do |reader|%>
- <%= reader.title%>
<% end %>
First off, your iterator code isn’t as clear as it could be.
Is @readers a collection?
If it’s not, then it should probably read…
@reader.magazines.each do |magazine|
Since within the block you are working with magazines and not readers
You should be able to access the subscription model directly from both
your reader and magazine models. If you can’t, you probably don’t have
it setup properly.
An example from some code I wrote a few days ago…
has_many :days, :through => :showings
has_many :showings, :dependent => :destroy
has_many :tickets, :through => :showings
I’d suggest playing around in the console to make absolutely certain
everything works before writing views. (Actually, I’d really suggest
you write unit tests to make sure everything works (and continues to
work as you write more code).)
Anywho, hope that helps out.