如何向rails4添加自定义谓词(http请求方法)

时间:2020-12-20 11:00:16

I want to add custom http VERB to rails 4 here is my routes.rb

我想在rails 4中添加自定义的http动词

ring "/session/" => "calls#ringing"

and I also puts this code to initializers

我也把这些代码放到初始化器中

%w(ring busy).each do |method|                                                                                                                                                                                                              
  ActionDispatch::Request::HTTP_METHODS << method.upcase                                                                                                                                                                                    
  ActionDispatch::Request::HTTP_METHOD_LOOKUP[method.upcase] = method.to_sym                                                                                                                                                                
end

When I try to start application I have this error.

当我尝试启动应用程序时,我有这个错误。

undefined method `ring' for #<ActionDispatch::Routing::Mapper:0x000000035c4150>

I really need to use this custom verb "RING".

我真的需要使用这个自定义动词“RING”。

1 个解决方案

#1


3  

I fixed the problem by adding to routes this string

我通过增加这个字符串的路由来解决这个问题

match '/session/:sessionid', :to => 'calls#initiate', :via => :ring 

#1


3  

I fixed the problem by adding to routes this string

我通过增加这个字符串的路由来解决这个问题

match '/session/:sessionid', :to => 'calls#initiate', :via => :ring