我试图通过Rails控制器将JSON数据发布到服务器。 我的ajax就像
$.ajax( {
url: "http://localhost:3000/widget_denemes/getUserInfo",
data: {userInfo: {mainURL:document.location.href}},
dataType: 'json',
type: 'POST',
success: function(data) {
alert("Successful");
},
error: function() {
alert("Unsuccessful");
}
});
我的控制器就像
def getUserInfo
data = ActiveSupport::JSON::decode(params[:userInfo])
format.json {head :ok}
end
我的路线也是
post 'widget_denemes/getUserInfo' => 'widget_denemes#getUserInfo'
但是当我运行服务器时,我在终端上看到了这个问题
Started POST "/widget_denemes/getUserInfo" for 127.0.0.1 at 2012-05-15 11:34:20 +0300
Processing by WidgetDenemesController#getUserInfo as HTML
Parameters: {"userInfo"=>{"mainURL"=>"file://localhost/Users/ender/Desktop/widgetTest.html"}}
Completed 500 Internal Server Error in 0ms
TypeError (can't convert ActiveSupport::HashWithIndifferentAccess into String):
app/controllers/widget_denemes_controller.rb:36:in `getUserInfo'
有什么不对? 我该如何解决?