2

特定のペアにデータを投稿しようとしてcontroller#actionいますが、アプリがPOSTでリダイレクトします(GETではありません)。その理由がわかりません。

私は1つの方法で必要最低限​​のコントローラーを構築しました:

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

私のルーティングファイルには1つのルールしかありません:

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

ただし、GETおよびPOSTを実行したときの結果は次のとおりです。

$ 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>

仕様:レール2.3.8、ルビー1.8.7

4

1 に答える 1

2

オフにしprotect_from_forgeryます。

すべてのコントローラー用

ApplicationControllerでコメントアウト(または削除)protect_from_forgeryします。

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

1つ以上のコントローラーの場合

skip_before_filter :verify_authenticity_tokenコントローラ宣言に追加します。

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

1つ以上のアクションの場合

:except上記skip_before_filterまたはprotect_from_forgeryコマンドにオプションを追加します。

class MyController < ApplicationController
    protect_from_forgery :except => :index
end

class MyOtherController < ApplicationController
    skip_before_filter :verify_authenticity_token, :except => [:create]
end
于 2012-12-13T18:01:12.420 に答える