相当多的链接,但我无法将所有信息拼凑在一起。
我假设涉及一个控制器、一个视图和路由。
关于 url 和路由,我有通用文件夹结构,app/views/pages/home 和 app/controllers/pages_controller.rb。如果我正确地执行路由和 url,你能指导我吗?
路线.rb
get pages/get_aj //Don't know if this is what you put
jQuery
$.ajax({
type: 'get'
url: '/pages/get_aj' //can someone confirm this is how you do it?
dataType: "JSON" //I need to pass back values from the controller to JS. Do I use JSON?
}).success(function(data){
alert("returned " + data);
});
//some other jQuery code that will depend on the data returned.
pages_controller.rb
def get_aj
respond_to do |format|
format.json{render :json => "we got here" } //Do I return .js?
end
end
耙路线
pages_home GET /pages/home(.:format) pages#home
pages_contact GET /pages/contact(.:format) pages#contact
pages_get_aj GET /pages/get_aj(.:format) pages#get_aj