我正在执行以下AJAX调用,并尝试解析Rails中收到的JSON,如下所示
AJAX
local_data = {chat:{room_name: chatRoomName ,message: message}}
$.ajax({
type: "POST",
url: '/chat_notify',
dataType: 'json',
async : false,
data: local_data,
success: function(data) {
alert("working");
}
});
红宝石
def notify
#data = ActiveSupport::JSON.decode(params)
#chat_room = ChatRoom.where(:slug => data.chat.name)
#puts @chat_room
puts params.chat
RestClient.post 'https://api.pushbots.com/push/all',
{ "platform" => [0,1] ,
"msg" => "Harsha sent a message." ,
"sound" => "pulse",
"alias" => "harsha@mink7.com",
"badge" => "1",
"payload" => { "type" => "Chat", "chat_id" => 1 } }.to_json,
headers = { "x-pushbots-appid" => APP_CONFIG['PUSHBOTS_APPID'],
"x-pushbots-secret" => APP_CONFIG['PUSHBOTS_SECRET'],
:content_type => :json }
render json: true
end
错误
答案 0 :(得分:0)
您需要粘贴错误跟踪
但我认为问题可能在下面
puts params.chat
params
没有聊天方法,只需删除它
或
…………"payload" => { "type" => "Chat", "chat_id" => 1 } }.to_json
您需要require 'json'
才能.to_json
可用