Rails 5.2
在我的config / routes.rb中,我有:
post 'books_author', to: 'books#author'
当我运行耙道时,我得到:
books_author POST /books_author(.:format) books#author
在我的app / controllers / books_controller.rb中,我有:
def author
books_collection = params[:books_collection]
author_notes = params[:author_notes]
render json: author_notes["2019"][author_notes]['main_author']
end
而且我认为,我有以下内容:
td
= link_to 'Author Details', books_author_path(books_collection: books_collection, author_notes: author_notes), method: :post
author_notes数据结构非常大。
[运行应用程序,然后单击链接时,出现以下错误消息:
This site can’t be reached
The connection was reset
我在浏览器中看到了这一点,但是development.log文件中没有任何条目。
如果双击顶部的浏览器栏将其选中,然后将其复制并粘贴到文本编辑器中,则会看到整个请求(很大的请求)。
我尝试传递一个较小的数据结构,并且效果很好。有什么想法如何将更大的数据结构从视图传递到控制器方法?
您需要在author
操作中进行一些更改,使用实例变量,以便可以在视图中对其进行访问
def author
@books_collection = params[:books_collection]
@author_notes = params[:author_notes]
render json: @author_notes["2019"][author_notes]['main_author']
end
在视图中
td
= link_to 'Author Details', books_author_path(books_collection: @books_collection, author_notes: @author_notes), method: :post
希望有帮助!