Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I think I am deeply misunderstanding how to write instances.

Miniatures have_many Manufacturers through the Productions table.

On the miniatures show page I am trying to list all the manufacturers for the current miniature and have them link the Manufacturer show page. Like so:

<% @miniature.manufacturers.each do |manufacturer| %>
    <%= link_to @miniature.manufacturer.name, manufacturer_path %>
<% end %>

Needless to say it does not work. It gives "undefined method `manufacturer'".

I have tried A LOT of different combinations to no avail. The following version puts all the manufacturers, rolled into one link, once for each manufacturer a miniature has, and links to /manufacturers. A big mess.

<% @miniature.manufacturers.each do |manufacturer| %>
    <%= link_to @miniature.manufacturers.map(&:name).join(', '), manufacturer_path %>
<% end %>

I have been working on other things and hoping I would get the hang of this but I'm pretty sure it's something pretty fundamental about how I set up the instance.

If it's more likely something I need to add to the controller then I can add my controller code here. Any help much appreciated.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
166 views
Welcome To Ask or Share your Answers For Others

1 Answer

Does this work:

<% @miniature.manufacturers.each do |manufacturer| %>
    <%= link_to manufacturer.name, manufacturer_path(manufacturer) %>
<% end %>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share

548k questions

547k answers

4 comments

86.3k users

...