Rails 4 - link_to 助手 - 关联对象的路径
Rails 4 - link_to helper - path to associated object
我正在尝试在 Rails 4.
中制作一个应用程序
我仍然对基本概念感到困惑。
我正在尝试在我的个人资料显示页面上放置一个 link 到相关组织的名称。
我有个人资料模型和组织模型。
关联是:个人资料属于组织和组织 has_many 个个人资料。
在我的个人资料显示页面上,我尝试了所有我能想到的不同方法来尝试为相关组织的组织显示页面制作 link。我试过:
<%= link_to @profile.organisation.try(:title).upcase, profile_organisation_path(organisation.id) %>
<%= link_to @profile.organisation.try(:title).upcase, profile_organisation_path(organisation_id) %>
<%= link_to @profile.organisation.try(:title).upcase, organisation_path(profile.organisation) %>
我已经尝试了大约 20 种变体。我不知道自己在做什么,也不明白如何阅读 API 文档。所以我卡住了。
谁能看出我做错了什么?
除了控制器,我想我明白发生了什么。尝试进行以下编辑
<%= link_to @profile.organisation.try(:title).upcase, organisation_path(@profile.organisation) %>
除非您以某种方式在别处设置了局部变量 organization,否则您需要使用您的实例变量来指定关联的组织,就像您在命名 link 时所做的那样。
尝试
<%= link_to @profile.organisation.try(:title).upcase, organisation_path(@profile.organisation.id) %>
我正在尝试在 Rails 4.
中制作一个应用程序我仍然对基本概念感到困惑。
我正在尝试在我的个人资料显示页面上放置一个 link 到相关组织的名称。
我有个人资料模型和组织模型。
关联是:个人资料属于组织和组织 has_many 个个人资料。
在我的个人资料显示页面上,我尝试了所有我能想到的不同方法来尝试为相关组织的组织显示页面制作 link。我试过:
<%= link_to @profile.organisation.try(:title).upcase, profile_organisation_path(organisation.id) %>
<%= link_to @profile.organisation.try(:title).upcase, profile_organisation_path(organisation_id) %>
<%= link_to @profile.organisation.try(:title).upcase, organisation_path(profile.organisation) %>
我已经尝试了大约 20 种变体。我不知道自己在做什么,也不明白如何阅读 API 文档。所以我卡住了。
谁能看出我做错了什么?
除了控制器,我想我明白发生了什么。尝试进行以下编辑
<%= link_to @profile.organisation.try(:title).upcase, organisation_path(@profile.organisation) %>
除非您以某种方式在别处设置了局部变量 organization,否则您需要使用您的实例变量来指定关联的组织,就像您在命名 link 时所做的那样。
尝试
<%= link_to @profile.organisation.try(:title).upcase, organisation_path(@profile.organisation.id) %>