【问题标题】:Linking to Dynamic Content in Rails?在 Rails 中链接到动态内容?
【发布时间】:2010-11-28 18:05:52
【问题描述】:

我有三个模型。用户、产品和季节。

我使用了标准的“多次通过”方法:

用户has_many :seasons
用户 has_many :products, :through => :seasons

产品has_many :seasons
产品 has_many :users, :through => :seasons

四季belong_to :product
四季belong_to :user

在我的用户“显示”视图中,我显示用户的产品。我这样做如下:

    <% @user.seasons.each do |c| %>
      <%=h c.product.name %>
    <% end %>  

这一切都很好。

这是我的问题。如何创建指向此代码 生成的任何产品的显示视图的超链接?我按照 API 并尝试使用块,但我的尝试都没有正常工作。

【问题讨论】:

    标签: ruby-on-rails views hyperlink


    【解决方案1】:
      <% @user.seasons.each do |c| %>
        <%= link_to c.product.name, c.product %>
      <% end %>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-03-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多