Rails4/mongoidアプリケーションでAPIに問題があります。私は、APIを介してのpython 3スクリプトを使用してデータを操作する必要があるが、私はリクエストを送信しようとすると、私はNoMethodError(未定義メソッド `permit_new_id ':String):
NoMethodError (undefined method `permit' for "note_id":String):
エラーを取得しています。
私のPythonのコードは、私は同じエラーでいくつかの質問を見ましたが、私の問題への解決策を見つけることができませんでした。この
import requests
import json
url = 'http://0.0.0.0:3000/api/v1/note_proc_logs.json'
payload = {'note_proc_log' : { 'note_id' : '120904'}}
head = {"Authorization":"Token token=xxxxxxxxxxxxxxxxxxx"}
r = requests.post(url, payload, headers=head)
のAPIのcontroler
module Api
module V1
# This class does not inherit from ApplicationController like the rest to skip Devise authentication
class NoteProcLogsController < ActionController::Base
before_filter :restrict_access if Rails.env.development? == false
respond_to :json
def create
Rails.logger.warn "note_proc_log_params: #{params}" if Rails.env.development?
@note_proc_log = NoteProcLog.new(note_proc_log_params)
respond_to do |format|
if @note_proc_log.save
format.json { render :show, status: :created, location: @note_proc_log }
else
format.json { render json: @note_proc_log.errors, status: :unprocessable_entity }
end
end
end
private
def restrict_access
authenticate_or_request_with_http_token do |token, options|
ApiKey.where(access_token: token).exists?
end
end
# Never trust parameters from the scary internet, only allow the white list through.
def note_proc_log_params
params.require(:note_proc_log).permit(:note_id)
end
end
end
end
のように見えます。
ご協力いただければ幸いです。
UPDATE:
Rails.logger.warn "note_proc_log_params: #{params}" if Rails.env.development?
問題はPythonスクリプトにあった私に
W, [2016-07-25T15:10:38.362848 #48352] WARN -- : params: {"note_proc_log"=>"note_id", "format"=>"json", "controller"=>"api/v1/note_proc_logs", "action"=>"create"}
開発中ですか?この行の結果を投稿できますか? Rails.logger.warn "note_proc_log_params:#{params}" if Rails.env.development? 私はparamsのフォーマットを見たいと思います。 – fabriciofreitag
あなたのペイロードがパラメータ用の適切なハッシュを生成していないと思います – hgsongra
ペイロードキーから空白を削除して、 'python code'でコロン': 'を、ここでは新しいpaylod' payload = {'note_proc_log':{'note_id': '120904 '} ' – hgsongra