【发布时间】:2017-11-12 13:55:36
【问题描述】:
我有两个模型,车辆模型和学生模型。我正在尝试从我的车辆索引视图链接到我的学生展示视图。但是,当我使用 link_to 时,我得到了 /students.0827312 的 url 的输出,并且我需要它作为 /students/0827312 在我的输出链接中,我不确定我错过了什么。我只是想弄清楚我需要调用什么来将 period 替换为 slash。
车辆.rb
class Vehicle < ApplicationRecord
self.primary_key = :vehicle_id
belongs_to :student, optional: true
学生.rb
class Student < ApplicationRecord
self.primary_key = :student_id
has_one :vehicle
/views/vehicles/index.html.erb
<%=link_to vehicle.student_id, students_path(vehicle.student_id) %>
rake route 命令
【问题讨论】:
-
只是关于术语的注释,您不会在模型之间进行链接。模型是不知道什么是链接的后端概念。您在概念上链接 actions,它们是请求的前端处理程序。
标签: ruby-on-rails link-to