Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby/24.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 如何在ruby-like-CakePHP中自动获取页面URL?_Ruby On Rails_Ruby_Cakephp - Fatal编程技术网

Ruby on rails 如何在ruby-like-CakePHP中自动获取页面URL?

Ruby on rails 如何在ruby-like-CakePHP中自动获取页面URL?,ruby-on-rails,ruby,cakephp,Ruby On Rails,Ruby,Cakephp,我是RubyonRails的初学者。我有一个users\u controller.rb还有很多action大约100多个。所以很难在路由器中设置。我想自动设置动作 示例: def abc render text: 'Hello World!' end ... ... def xyz render text: 'Bla Bla Bla' end 我想我的URL应该是打开这种类型 http://localhost:3000/users/abc http://localhost:3000

我是RubyonRails的初学者。我有一个
users\u controller.rb
还有很多
action
大约100多个。所以很难在路由器中设置。我想自动设置动作

示例:

def abc
   render text: 'Hello World!'
end
...
...
def xyz
   render text: 'Bla Bla Bla'
end
我想我的URL应该是打开这种类型

http://localhost:3000/users/abc
http://localhost:3000/users/xyz
http://localhost:3000/users/some-action..
不需要在路由器中设置任何多行URL路径

下面是我在路由器上写的。如果代码不起作用:

match ':controller(/:action(/:id(.:format)))'

请帮助我使用您的代码时遇到的错误是:

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]

请注意
,通过:[:获取,:发布]

是,工作正常。以前我在路由器中设置了其他路径。以下
match':controller(/:action(/:id(:format))”,通过:[:get,:post]
,是否受影响?Rails路由工作如下:您有一个
config\routes.rb
文件。轨道将从上到下循环通过每条线路。如果当前url与当前行的路由匹配,那么Rails将停止并使用该路由,否则将转到下一行。基于此,我想您应该理解,如果您将
match':controller(/:action(/:id(:format)),via:[:get,:post]
放在您的文件顶部,那么它(几乎)将始终匹配路由,因此下面的所有行都将无效。结论是:将这一行放在
routes.rb的底部。更多信息:你们需要应用程序中所有控制器的这种类型的东西吗?或者某个特定的控制器我认为你们不应该使用这种东西什么是
dnd
。。。。。。很抱歉打字错误。我只是举个例子。:)@sawa更新了我的问题。请查收