Reputation: 6244
In a rails 3.2 app I am having trouble getting a page to render when a get request is issued by jQuery.
In a page:
<%= select_tag 'bah', options_from_collection_for_select(@groups, :id, :name, ""), :class => "get_to_edit" %>
In my js file:
$(".get_to_edit").change(function() {
var id = $(this).val();
var url = "/groups/" + id + "/edit"
$.get(url, id, function(html) {
});
});
In my controller:
def edit
@group = Group.find(params[:id])
end
In my terminal I'm getting:
Rendered groups/edit.html.erb within layouts/application (4.8ms)
Yet, nothing is rendered and no error is indicated.
Thanks for your help.
Upvotes: 1
Views: 44
Reputation: 852
Maybe you didn't copy/paste it but inside your $.get success callback you aren't doing anything with what is returned by the request.
You need something to this effect (to at least debug the return in the developer console):
$.get(url, id, function(data, textStatus, xhr) {
console.log(data);
});
I would recommend looking into some of the built in javascript helpers Rails provides. It can do a lot of this for you: http://railscasts.com/episodes/205-unobtrusive-javascript?view=asciicast may be of some help.
Upvotes: 1