I have a model "wanted_offers" that''s defined as a "belongs_to" with another model. All that wanted_offers has is two foreign keys in two columns. I''ve implemented a show method and passing in the id of the wanted_offer that the user clicks on. The method is not displaying anything. The "<% for column in WantedOffer.content_columns %>" isn''t executing. When I look at the database, it looks as expected with two rows. mysql> select * from wanted_offers; +----+---------+---------+ | id | user_id | book_id | +----+---------+---------+ | 2 | 5 | 2 | | 3 | 5 | 3 | +----+---------+---------+ 2 rows in set (0.00 sec) column_names seems to return the right results>> WantedOffer.column_names=> ["id", "user_id", "book_id"] However, content_columns is returning nothing :-(>> WantedOffer.content_columns=> [] Any ideas why? --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Me again... I suppose Ruby is doing the RIGHT thing by returning null on content_columns call since the child doesn''t have any content per se - it just holds two foreign keys. So maybe I can restate my Q... How do I get at a parent of WantedOffer in this type of call? <% for column in WantedOffer.content_columns %> On Feb 15, 11:23 am, nahabed <roup...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> I have a model "wanted_offers" that''s defined as a "belongs_to" with > another model. All that wanted_offers has is two foreign keys in two > columns. > > I''ve implemented a show method and passing in the id of the > wanted_offer that the user clicks on. > > The method is not displaying anything. The "<% for column in > WantedOffer.content_columns %>" isn''t executing. > > When I look at the database, it looks as expected with two rows. > mysql> select * from wanted_offers; > +----+---------+---------+ > | id | user_id | book_id | > +----+---------+---------+ > | 2 | 5 | 2 | > | 3 | 5 | 3 | > +----+---------+---------+ > 2 rows in set (0.00 sec) > > column_names seems to return the right results>> WantedOffer.column_names > > => ["id", "user_id", "book_id"] > > However, content_columns is returning nothing :-(>> WantedOffer.content_columns > > => [] > > Any ideas why?--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
nahabed,
I''m not sure that rendering for .content_columns is something
you''d
want to do in production. It may get things out quickly for
development but I''d suspect you will quickly want more control that
what that will allow.
As to your real question... I''m making an assumption from the keys in
your wanted_offers db that you might be able to build your classes
like this:
class User
has_many :wanted_offers
has_many :wanted_books :through=>:wanted_offers,
:class_name=>''Book'',
...
end
(You should mirror this in Book)
With that in place you should be able to do something like this:
@user.wanted_books.each do |book|
book.content_columns.each do |book_column|
...whatever it is you were trying to do...
end
end
HTH,
AndyV
On Feb 15, 4:27 pm, nahabed
<roup...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
wrote:> Me again... I suppose Ruby is doing the RIGHT thing by returning null
> on content_columns call since the child doesn''t have any content
per
> se - it just holds two foreign keys. So maybe I can restate my Q...
>
> How do I get at a parent of WantedOffer in this type of call? <% for
> column in WantedOffer.content_columns %>
>
> On Feb 15, 11:23 am, nahabed
<roup...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:
>
> > I have a model "wanted_offers" that''s defined as a
"belongs_to" with
> > another model. All that wanted_offers has is two foreign keys in two
> > columns.
>
> > I''ve implemented a show method and passing in the id of the
> > wanted_offer that the user clicks on.
>
> > The method is not displaying anything. The "<% for column in
> > WantedOffer.content_columns %>" isn''t executing.
>
> > When I look at the database, it looks as expected with two rows.
> > mysql> select * from wanted_offers;
> > +----+---------+---------+
> > | id | user_id | book_id |
> > +----+---------+---------+
> > | 2 | 5 | 2 |
> > | 3 | 5 | 3 |
> > +----+---------+---------+
> > 2 rows in set (0.00 sec)
>
> > column_names seems to return the right results>>
WantedOffer.column_names
>
> > => ["id", "user_id", "book_id"]
>
> > However, content_columns is returning nothing :-(>>
WantedOffer.content_columns
>
> > => []
>
> > Any ideas why?
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---