【发布时间】:2016-04-19 02:49:40
【问题描述】:
我正在尝试弄清楚如何使用 Rails 4 制作应用程序。我一直卡在基本的东西上,似乎无法确定要使用的原则。
我有一个简介模型和一个行业模型。这些关联是:
简介:
has_and_belongs_to_many :industries, join_table: 'industries_profiles'
行业:
has_and_belongs_to_many :profiles, join_table: 'industries_profiles'
在我的个人资料显示页面中,我现在正在尝试链接到行业页面:
<% @profile.industries.limit(5).each do |industry| %>
<%= link_to industry.sector.upcase, industry_path(@industry) %>
<% end %>
我找不到任何适用于此链接的内容。
我尝试了以下方法:
industry_path(@profile.industry)
industry_path(@profile.industry_id)
industry_path(industry)
industry_path(profile.industry)
industry_path(industry.id)
industry_path(industry_id)
但所有这些都是猜测。我不知道如何准备 API Dock,所以我无法理解它的任何内容。
任何人都可以看到如何链接到 HABTM 关联另一方的显示页面以获取单个记录吗?
【问题讨论】:
-
你的 routes.rb 文件有什么?
industry_path(industry)是您应该使用的。 -
我有:资源:行业
-
当我尝试这样做时,当我将鼠标悬停在链接上时,它会显示一个包含正确行业 ID 的路径。但我无法点击它 - 没有任何反应
-
正如 Ben 所说,
industry_path(industry)应该可以工作,你所说的“什么都没有发生”是什么意思?如果 href 上面有 id,那么它工作正常 -
试试这个方法:
标签: ruby-on-rails ruby-on-rails-4 path associations link-to