我是一个 Rails 新手,并且有一个看似微不足道/基本的 Rails 问题。
我有一个链接,我试图在其中传递有关对象的信息:
<% for author in @book.authors %>
<%= link_to "compute", special_book_path(author) %>
如何访问控制器中的“作者”对象(通过特殊命名路由传递)?
我试过:
@author = @book.authors.find(params[:author])
但出现“找不到没有 ID 的作者”错误。
编辑:解决方案
special_book_path(author_id: author.id)
控制器
params[:author_id]