Why does Rails redirect my POST but not GET?

I am trying to send data to a specific controller#action pair, but my application redirects me to POST (but not GET), and I cannot understand why.

I built the bare-bones controller in one way:

 class NavigationsController < ApplicationController def foo render :text => 'in foo' end end 

There is only one rule in my routing file:

 map.connect ':controller/:action/:id' 

Here is 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> 

characteristics: rails 2.3.8, ruby ​​1.8.7

+2
source share
1 answer

Disable protect_from_forgery .

For all controllers

Commenting (or deleting) protect_from_forgery in ApplicationController.

 class ApplicationController < ActionController::Base #protect_from_forgery # See ActionController::RequestForgeryProtection for details # ... end 

For one or more controllers

Add skip_before_filter :verify_authenticity_token to the controller declaration.

 class NavsController < ApplicationController skip_before_filter :verify_authenticity_token # ... end 

For one or more actions

Add the :except option to previous skip_before_filter or protect_from_forgery .

 class MyController < ApplicationController protect_from_forgery :except => :index end class MyOtherController < ApplicationController skip_before_filter :verify_authenticity_token, :except => [:create] end 
+2
source

All Articles