jeffp/wizardly

ActionController::MethodNotAllowed: Only get and post requests are allowed.

Opened this issue · 3 comments

My app fails in the guard_entry method where ::ActionController::Routing::Routes.recognize_path(path) statement is run, regardless of :guard option to act_as_wizard.

def guard_entry 
  if (r = request.env['HTTP_REFERER'])
    h = ::ActionController::Routing::Routes.recognize_path(URI.parse(r).path)
    return check_progression if (h[:controller]||'') == '#{self.controller_name}'
    self.initial_referer = h unless self.initial_referer
  end

Here is a reproducible snippet:

>> ::ActionController::Routing::Routes.recognize_path("/packages", {})
ActionController::MethodNotAllowed: Only get and post requests are allowed.
    from /home/mog/work/kistamassan/vendor/rails/actionpack/lib/action_controller/routing/recognition_optimisation.rb:64:in `recognize_path'
    from (irb):14

However if i pass in :method => :get option it works fine.

>> ::ActionController::Routing::Routes.recognize_path("/packages", {:method => :get})
=> {:action=>"index", :controller=>"packages"}

This happens for routes that have :conditions => { :method => :get } defined and includes all routes defined by map.resources. If the request comes from one of these URLs this error will happen.

Commited fix in http://github.com/morganchristiansson/wizardly/commit/c614305e8a92d263e7a827f9fef8a0518eea226f

Let me know if you think this is correct.

Regards,
Morgan

Thanks Morgan. Looked into the problem. I believe your solution suffices except for the situation where a request comes from a resource without an available GET method. But I think this is rectified by wrapping as such

begin
h = ::ActionController::Routing::Routes.recognize_path(URI.parse(r).path, {:method=>:get})
rescue
else
return check_progression if (h[:controller]||'') == '#{self.controller_path}'
self.initial_referer = h unless self.initial_referer
end

I've tested and regemed. If this works for you, I'll close this issue.

Regards,
Jeff

sorry, code was not very readable... try this


begin
  h = ::ActionController::Routing::Routes.recognize_path(URI.parse(r).path, {:method=>:get})
rescue
else
  return check_progression if (h[:controller]||'') == '#{self.controller_path}'   self.initial_referer = h unless self.initial_referer 
end