简体   繁体   English

从Ruby on Rails的视图中传回对象

[英]Passing Object back from view on Ruby on rails

I tried this: 我尝试了这个:

th = link_to "ID", results_path(sort: "id", search_form: @search_form)

to return the instance @search_form to the controller "results", but that returns a nil variable, but I have to point out that the sort variable accessed on the controller in this way params[:sort] has the correct value, so the path works. 返回实例@search_form到控制器“结果”,但是返回一个nil变量,但是我必须指出,以这种方式在控制器上访问的排序变量params[:sort]具有正确的值,因此路径作品。

So now I have to return every single attribute by its own and this is the solution that works 所以现在我必须返回每个单独的属性,这是可行的解决方案

th = link_to "ID",
                      :sort => "id",
                      :verweildauer => @search_form.verweildauer,
                      :datenjahr => @search_form.datenjahr,
                      :drgsystem => @search_form.drgsystem,
                      :greatersmallerequal => @search_form.greatersmallerequal,
                      :patients_per_page => @search_form.patients_per_page

then I have to rebuild the object on the controller accessing every single attribute. 那么我必须在访问每个属性的控制器上重建对象。

How can I directly pass in the @search_form into the controller? 如何直接将@search_form传递给控制器​​?

If I correctly understand you want to pass many filter params to the get/link_to. 如果我正确理解,您想将许多过滤器参数传递给get / link_to。 It is a bad idea because of get request query size limit. 由于获取请求查询的大小限制,这是一个坏主意。 You should use form tag here and move all your params to hidden fields. 您应该在此处使用表单标签,并将所有参数移至隐藏字段。 This is the right way. 这是正确的方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM