How to access instance variable from ajax?
I have a model named User and in its index.html.erb file, has a link which
calls an ajax request responsible for retrieving user's authenticated
radars. There it is:
//user.js
function retrieve_radars() {
$.ajax({
type: "GET",
url: "/radars",
success: function(data) {
console.log(data);
}
});
}
#app/controllers/radars_controllers.rb
def index
user = current_user;
@radars = Radar.where(:user_id => user.id)
@radars
end
How could I iterate @radars instance variable in "users/index.html.erb",
after the success ajax response? I would like to do something like this:
<% unless @radars.nil? %>
<table>
<% @radars.each do |radar| %>
<tr>
<td>Name</td>
<td><%= radar.name %></td>
</tr>
<% end %>
</table>
<% end %>
Any help? Thanks
No comments:
Post a Comment