Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby/23.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 URL参数的基本路由_Ruby On Rails_Ruby - Fatal编程技术网

Ruby on rails URL参数的基本路由

Ruby on rails URL参数的基本路由,ruby-on-rails,ruby,Ruby On Rails,Ruby,我的目标只是在索引页上显示两个可选的URL参数 0.0.0.0:3000/比较->显示:空比较索引页 0.0.0.0:3000/比较/3->显示: 3 0.0.0.0:3000/比较/3/4->显示: 3 4 我创建了一个控制器+视图进行比较 rails generate controller comparison 我补充说 match ':comparison/:index(/:a(/:b))' 并添加了一个index.html.erb来显示这两个参数 <%= @a %>

我的目标只是在索引页上显示两个可选的URL参数

0.0.0.0:3000/比较->显示:空比较索引页

0.0.0.0:3000/比较/3->显示:

3
0.0.0.0:3000/比较/3/4->显示:

3
4 
我创建了一个控制器+视图进行比较

rails generate controller comparison
我补充说

match ':comparison/:index(/:a(/:b))'
并添加了一个index.html.erb来显示这两个参数

<%= @a %>
<%= @b %>

如何正确选择路由?

假设Rails版本3.x:

match 'comparison(/:a(/:b))' => "comparison#index"

它是否真的匹配:comparison/:index/:a/:b'和not match'comparison/:index/:a/:b'?我更改了它。现在我得到了错误参数error:missing:controllertry this->通过querystring捕捉多个ID
Routing Error

No route matches [GET] "/comparison/3/4"
match 'comparison(/:a(/:b))' => "comparison#index"