![](/img/trans.png)
[英]how to display one controller show action in another controller action in rails
[英]How to access URL in Rails Show action in Controller
这是我想在我的显示方法中访问的 URL
http://localhost:3000/students.1
ActiveRecord::RecordNotFound in StudentsController#show 找不到具有 'id'= 的学生
定义显示
@student = Student.find(params[:id])
我的路线是
new_students GET /students/new(.:format) 学生#new
edit_students GET /students/edit(.:format) 学生#edit
students GET /students(.:format) students#show
PATCH /students(.:format) students#update
PUT /students(.:format) students#update
DELETE /students(.:format) students#destroy
POST /students(.:format) students#create
root GET / students#index
有人可以告诉我如何在我的 URL 中访问该 students.1 以便我可以在我的显示页面上显示该特定学生吗?
你的路线形成有问题
你的 url 没有正确成型,试试下面
students_path(id: student.id)
应该是http://localhost:3000/students/1
查看此文档
那是错误的道路。 它应该是/students/1
。
而且你的路线是错误的。 您可以通过缺少 id 段以及将GET /students
映射到 show 操作而不是索引这一事实来判断路由已关闭。
# Wrong
resource :students
# Right
resources :students
复数化在 Rails 中极为重要,值得认真关注。 虽然只是一个小字母,但这些方法会产生完全不同的路线。
resource
用于奇异资源。 这不是这里的情况。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.