Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/61.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails Rails命名路由和参数_Ruby On Rails_Routes - Fatal编程技术网

Ruby on rails Rails命名路由和参数

Ruby on rails Rails命名路由和参数,ruby-on-rails,routes,Ruby On Rails,Routes,我想向我的控制器发送一些数据,然后在变量中: 参数[:oem_编号] 参数[:id] 看到了一些数据,但我怎样才能发送到方法数据呢?如何写这条路线? 现在我有了这样的路线: match '/articles/by_oem/:id&:oem_number' => 'articles#articles_by_oem', :as => :articles_by_oem 并尝试创建链接: = link_to "аналоги", :articles_by_oem(:id

我想向我的控制器发送一些数据,然后在变量中:

  • 参数[:oem_编号]
  • 参数[:id]
看到了一些数据,但我怎样才能发送到方法数据呢?如何写这条路线? 现在我有了这样的路线:

  match '/articles/by_oem/:id&:oem_number' => 'articles#articles_by_oem', :as => :articles_by_oem
并尝试创建链接:

 = link_to "аналоги", :articles_by_oem(:id => no.article_nr, :oem_number => no.oem)
但我有语法错误

那么如何解决我的问题呢?请不要把我送到rails医生的


如何创建链接,发送这两个参数,以及在编辑路由之前…

首先,您不需要路由上的参数列表。
= link_to "name", articles_by_oem_path(no.article_nr, no.oem)
您可以将此内容保留在您的
路由器中。rb

/articles/by_oem/:id
那么,你想在这里做什么

:articles_by_oem(:id => no.article_nr, :oem_number => no.oem)
:oem的文章是一个符号,而不是功能。改用
articles\u by\u oem\u path
方法:


还需要我写/articles/by_oem/:id或articles/by_oem/:id是否相等?是的,它们是相等的。但更常见的是出现斜杠。
= link_to "аналоги", articles_by_oem_path(:id => no.article_nr, :oem_number => no.oem)