如何像CakePHP一样自动获取ruby中的页面URL?

时间:2016-05-20 06:33:05

标签: ruby-on-rails ruby cakephp

我是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)))'

请帮帮我

1 个答案:

答案 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.2ruby 2.3.0上有以下作品:

match ':controller(/:action(/:id(.:format)))', via: [:get, :post]

请注意, via: [:get, :post]