有人可以帮我解决这个错误吗? 我有一个collection_select,onchange触发我的javascript到ajax回到Controller(Demographics)动作(demo_set)。这就是我想要完成的事情。 让我们来看看它:
查看代码:
<%= collection_select( :demographic, :demographic_id, Demographic.all, :id, :fullName,{}, {:onChange => "selectDemo(4);"}) %>
使用Javascript:
function selectDemo(id) {
//alert(id);
$.ajax({
url: "/demographics/" + id + "/demo_set",
context: document.body
}).done(function() {
$( this ).addClass( "done" );
});
}
如你所见,这个AJAX正在调用
http://localhost:3000/demographics/4/demo_set
转到此链接会在人口统计信息中显示&#34; NoMethodError#demo_set&#34;错误
routes.rb中:
get "/demographics/:id/demo_set" => "demographics#demo_set"
demographics_controller:
def demo_set
render "activities/index"
end
activities_controller:
def index
@activities = Activity.all
end
感谢您的帮助