How to add custom verb (http request method ) to rails4

空扰寡人 提交于 2019-12-10 21:03:53

问题


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

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".


回答1:


I fixed the problem by adding to routes this string

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


来源:https://stackoverflow.com/questions/18065443/how-to-add-custom-verb-http-request-method-to-rails4

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!