Reputation: 30226
I'm trying to post data to a certain controller#action
pair, but my app redirects me on POST (but not GET), and I can't figure out why.
I built a bare-bones controller with one method:
class NavigationsController < ApplicationController
def foo
render :text => 'in foo'
end
end
My routing file has only one rule:
map.connect ':controller/:action/:id'
Here's my result when I GET and POST, though:
$ curl http://localhost:3000/navigations/foo/1
in foo
$ curl -d 'a=b' http://localhost:3000/navigations/foo/1
<html><body>You are being <a href="http://localhost:3000/">redirected</a>.</body></html>
specs: rails 2.3.8, ruby 1.8.7
Upvotes: 2
Views: 262
Reputation: 30226
Turn off protect_from_forgery
.
Commenting out (or delete) protect_from_forgery
in ApplicationController.
class ApplicationController < ActionController::Base
#protect_from_forgery # See ActionController::RequestForgeryProtection for details
# ...
end
Add skip_before_filter :verify_authenticity_token
to the controller declaration.
class NavsController < ApplicationController
skip_before_filter :verify_authenticity_token
# ...
end
Add an :except
option to the foregoing skip_before_filter
or protect_from_forgery
commands.
class MyController < ApplicationController
protect_from_forgery :except => :index
end
class MyOtherController < ApplicationController
skip_before_filter :verify_authenticity_token, :except => [:create]
end
Upvotes: 2