Quite a bit of links, but I can't piece all of the info together.
I assume a controller, a view and routes are involved.
Regarding the url and routes, I have the generic folder structure, app/views/pages/home and app/controllers/pages_controller.rb. Can you guide me if I'm doing the routing and url correctly, also?
routes.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
rake routes
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
format.jsontoformat.jsand post yourrake routesregarding the pages_controller and the console messageformat.js, also what does the console in your browser say?