Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/53.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 铁路3路线问题_Ruby On Rails_Routing_Ruby On Rails 3 - Fatal编程技术网

Ruby on rails 铁路3路线问题

Ruby on rails 铁路3路线问题,ruby-on-rails,routing,ruby-on-rails-3,Ruby On Rails,Routing,Ruby On Rails 3,这可能很简单,但如何使参数成为可选的 resources :places match 'register/:id' => 'places#new', :as => :register 目前。。。如果未传递:id,它将中断,而大多数情况下不会传递 <%= link_to "Place Sign Up", register_path %> 查看config/routes.rb的最后一行 match ':controller(/:action(/:id(.:format)

这可能很简单,但如何使参数成为可选的

resources :places
match 'register/:id' => 'places#new', :as => :register
目前。。。如果未传递
:id
,它将中断,而大多数情况下不会传递

<%= link_to "Place Sign Up", register_path %> 

查看
config/routes.rb的最后一行

match ':controller(/:action(/:id(.:format)))'
在您的情况下,它使用
()
将参数设置为可选:

'register(/:id)'