railsを起動しcisco merakiのダッシュボードからScanning APIのPOSTs URLを追加しようとURLを入れてrails側にGETリクエストを送り、それに対しRailsがValidatorの値をPOSTで返したところ、下記のエラーメッセージが出てきました。
Started POST "/personal_logs" for 127.0.0.1 at 2018-07-26 12:03:23 +0900 Processing by PersonalLogsController#presenceapi as HTML Parameters: {"version"=>"2.0", "secret"=>""... . . }, "seenTime"=>"2018-07-26T03:02:38Z", "ssid"=>nil, "os"=>nil, "clientMac"=>"20:ab:37:", "seenEpoch"=>15325158, "rssi"=>9, "ipv6"=>nil, "manufacturer"=>"Apple"}]}}} Completed 500 Internal Server Error in 2ms (ActiveRecord: 0.0ms) TypeError (no implicit conversion of ActionController::Parameters into String): app/controllers/personal_logs_controller.rb:12:in `presenceapi'
app/controllers/personal_logs_controller.rbの
map = JSON.parse(params[:data]).with_indifferent_access
ここ周辺に原因があるようですが、どうアプローチしていいかわかりません。
下記に該当コードを載せておきます
本当に困ってるのでどうかお力を貸して頂きたいです
ruby
1#app/controllers/personal_logs_controller 2MERAKI_VALIDATOR='xxxxxxxxxxxxxxxxxxxxxxxxxx' 3MERAKI_SECRET = 'xxxxxxxx' 4 5class PersonalLogsController < ApplicationController 6 skip_before_action :verify_authenticity_token 7 before_action :set_personal_log, only: [:show, :edit, :update, :destroy] 8 9 def presenceapi 10 if request.post? 11 map = JSON.parse(params[:data]).with_indifferent_access 12 if map[:secret] == MERAKI_SECRET 13 map[:probing].each do |p| 14 Presence.create(ap_mac: p[:ap_mac], client_mac: p[:client_mac], 15 last_seen: DateTime.parse(p[:last_seen]), 16 rssi: p[:rssi]) 17 end 18 render :text => '' and return 19 else 20 Rails::logger.warn("*** MERAKI req with bad secret '#{map[:secret]}'") 21 rails 'access denied' 22 end 23 else 24 render :plain => MERAKI_VALIDATOR 25 end 26 end 27end
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。