किसी कारण से मुझे जेसन या एक्सएमएल का उपयोग करते समय मेरे आवेदन में पोस्ट अनुरोध करते समय अमान्य प्रमाणीकरण टोकन मिल रहा है। मेरी समझ यह है कि रेलों को केवल एचटीएमएल या जेएस अनुरोधों के लिए प्रामाणिकता टोकन की आवश्यकता होनी चाहिए, और इस प्रकार मुझे इस त्रुटि का सामना नहीं करना चाहिए। एकमात्र समाधान जो मैंने पाया है, वह एपीआई के माध्यम से किसी भी कार्रवाई के लिए protect_from_forgery को अक्षम कर रहा है, लेकिन यह स्पष्ट कारणों से आदर्श नहीं है। विचार?रेल - अमान्य प्रमाणीकरण टोकन जेएसएन/एक्सएमएल अनुरोधों के लिए
def create
respond_to do |format|
format.html
format.json{
render :json => Object.create(:user => @current_user, :foo => params[:foo], :bar => params[:bar])
}
format.xml{
render :xml => Object.create(:user => @current_user, :foo => params[:foo], :bar => params[:bar])
}
end
end
और यह है कि क्या मैं लॉग में मिलता है जब भी मैं कार्रवाई के लिए एक अनुरोध भेज देता है:
Processing FooController#create to json (for 127.0.0.1 at 2009-08-07 11:52:33) [POST]
Parameters: {"foo"=>"1", "api_key"=>"44a895ca30e95a3206f961fcd56011d364dff78e", "bar"=>"202"}
ActionController::InvalidAuthenticityToken (ActionController::InvalidAuthenticityToken):
thin (1.2.2) lib/thin/connection.rb:76:in `pre_process'
thin (1.2.2) lib/thin/connection.rb:74:in `catch'
thin (1.2.2) lib/thin/connection.rb:74:in `pre_process'
thin (1.2.2) lib/thin/connection.rb:57:in `process'
thin (1.2.2) lib/thin/connection.rb:42:in `receive_data'
eventmachine (0.12.8) lib/eventmachine.rb:242:in `run_machine'
eventmachine (0.12.8) lib/eventmachine.rb:242:in `run'
thin (1.2.2) lib/thin/backends/base.rb:57:in `start'
thin (1.2.2) lib/thin/server.rb:156:in `start'
thin (1.2.2) lib/thin/controllers/controller.rb:80:in `start'
thin (1.2.2) lib/thin/runner.rb:174:in `send'
thin (1.2.2) lib/thin/runner.rb:174:in `run_command'
thin (1.2.2) lib/thin/runner.rb:140:in `run!'
thin (1.2.2) bin/thin:6
/opt/local/bin/thin:19:in `load'
/opt/local/bin/thin:19
यह वास्तव में वेब अनुप्रयोगों के लिए हालांकि काम नहीं करता। ब्राउज़र कर्ल नहीं चला सकते हैं। = ( – NullVoxPopuli
बिंदु यह था कि मैंने इस मुद्दे को कर्ल से डीबग किया और पाया कि सही सामग्री-प्रकार शीर्षलेख भेजना महत्वपूर्ण था। – mlambie