ruby-on-rails – 如何定义链接路径
发布时间:2020-12-17 01:56:25 所属栏目:百科 来源:网络整理
导读:我正在试图弄清楚如何使用Rails 4创建一个应用程序.我一直在坚持基本的东西,我似乎无法确定使用前进的原则. 我有个人资料模型和行业模型.协会是: 轮廓: has_and_belongs_to_many :industries,join_table: 'industries_profiles' 行业: has_and_belongs_to
我正在试图弄清楚如何使用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协会另一侧的节目页面的单个记录? 解决方法
您可以通过运行rake routes来获取路由列表命令行中的grep行业,它将为您提供一个包含前缀,操作和uri模式的表.例如:
industries GET /industries(.:format) industries#index POST /industries(.:format) industries#create new_industry GET /industries/new(.:format) industries#new edit_industry GET /industries/:id/edit(.:format) industries#edit industry GET /industries/:id(.:format) industries#show PATCH /industries/:id(.:format) industries#update PUT /industries/:id(.:format) industries#update DELETE /industries/:id(.:format) industries#destroy 在您的情况下,您应该查看显示路径.哪个是行业,你将_path附加到上面的任何前缀的末尾,这就是industry_path.既然您在定义循环时声明了变量行业,则可以使用它而不是实例变量. 简短回答:industry_path(行业) (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |