我是Ruby on Rails的初学者。我有users_controller.rb
有很多action
大约100多个。因此很难在路由器中设置。我想自动设置动作。
示例:
def abc
render text: 'Hello World!'
end
...
...
def xyz
render text: 'Bla Bla Bla'
end
我希望我的网址应该打开此类型
http://localhost:3000/users/abc
http://localhost:3000/users/xyz
http://localhost:3000/users/some-action..
无需在路由器中设置任何多行URL路径。
下面我在路由器中写道。不能使用该代码:
match ':controller(/:action(/:id(.:format)))'
请帮帮我
答案 0 :(得分:3)
我使用您的代码时遇到的错误是:
You should not use the `match` method in your router without specifying an HTTP method. (ArgumentError)
If you want to expose your action to both GET and POST, add `via: [:get, :post]` option.
在Rails 4.2.5.2
和ruby 2.3.0
上有以下作品:
match ':controller(/:action(/:id(.:format)))', via: [:get, :post]
请注意, via: [:get, :post]
。