I'm using this to post some information to a rails app. Problem is that it is just posting to the application controller.

我正在使用它将一些信息发布到rails应用程序。问题是它只是发布到应用程序控制器。

How can I get it so that the url is positing to :controller => 'analytics', :action => 'test'

我怎样才能得到它以便url定位到:controller =>'analytics',:action =>'test'

2 个解决方案

#1


8  

The path to your url (analytics/test) is relative, meaning it will be appended to the "directory" of the url you are working in. E.g. if you are calling this from http://yourhost.com/analytics/demo, you will call http://yourhost.com/analytics/analytics/test, which you probably do not want.

您的网址(分析/测试)的路径是相对的,这意味着它将附加到您正在使用的网址的“目录”中。例如。如果您从http://yourhost.com/analytics/demo调用此函数,您将调用http://yourhost.com/analytics/analytics/test,这可能是您不想要的。

Add a slash to the beginning (so you get /analytics/test) and you're fine.

在开头添加一个斜杠(这样你得到/ analytics / test)就可以了。

$.ajax({
    type: "POST",
    url: "/analytics/test",
    data: 'correct=' + correct_or_incorrect + '&id=' + correctCharacter[3] + "'"
});

#2


2  

None of the answerees know about rails and routes... at least that is what I'm assuming because nobody got close to this one.

答案中没有人知道铁路和路线...至少这是我所假设的,因为没有人接近这个。

$.ajax({ 
    url: '/analytics.json', 
    type: 'POST', 
    dataType: 'json', 
    success: 'success' 
 });

That's the answer :) - makes me very happy! Two days to get that one.

这就是答案:) - 让我很开心!两天就得到那个。

The problem was because of the url. I had :analytics declared in routes.rb but I didn't have the url correct and that is how rails deals with routes in particular RESTful routing.

问题是因为网址。我有:在routes.rb中声明的分析,但我没有正确的url,这就是rails如何处理特定RESTful路由中的路由。

Anyone using the code above should not that they can use html xml or whatever but you need to use that as the file extension instead of using .json

使用上述代码的任何人都不应该使用html xml或其他任何东西,但你需要使用它作为文件扩展名而不是使用.json

#1


8  

The path to your url (analytics/test) is relative, meaning it will be appended to the "directory" of the url you are working in. E.g. if you are calling this from http://yourhost.com/analytics/demo, you will call http://yourhost.com/analytics/analytics/test, which you probably do not want.

您的网址(分析/测试)的路径是相对的,这意味着它将附加到您正在使用的网址的“目录”中。例如。如果您从http://yourhost.com/analytics/demo调用此函数,您将调用http://yourhost.com/analytics/analytics/test,这可能是您不想要的。

Add a slash to the beginning (so you get /analytics/test) and you're fine.

在开头添加一个斜杠(这样你得到/ analytics / test)就可以了。

$.ajax({
    type: "POST",
    url: "/analytics/test",
    data: 'correct=' + correct_or_incorrect + '&id=' + correctCharacter[3] + "'"
});

#2


2  

None of the answerees know about rails and routes... at least that is what I'm assuming because nobody got close to this one.

答案中没有人知道铁路和路线...至少这是我所假设的,因为没有人接近这个。

$.ajax({ 
    url: '/analytics.json', 
    type: 'POST', 
    dataType: 'json', 
    success: 'success' 
 });

That's the answer :) - makes me very happy! Two days to get that one.

这就是答案:) - 让我很开心!两天就得到那个。

The problem was because of the url. I had :analytics declared in routes.rb but I didn't have the url correct and that is how rails deals with routes in particular RESTful routing.

问题是因为网址。我有:在routes.rb中声明的分析,但我没有正确的url,这就是rails如何处理特定RESTful路由中的路由。

Anyone using the code above should not that they can use html xml or whatever but you need to use that as the file extension instead of using .json

使用上述代码的任何人都不应该使用html xml或其他任何东西,但你需要使用它作为文件扩展名而不是使用.json

标签:

相关文章