javascript - Jquery file with variable id as selector with Ajax -
i want change micropost list element using ajax request. there several microposts in page. html file looks this.
<div class="load-more-<%= micropost.id %>" > <ol class="answers" > <%= render answers %> </ol> <%= link_to "more",more_micropost_path(micropost),remote: true %> </div> `
i want load _all_answers.html.erb when more link clicked using ajax. js file is
$(".load-more-<%= escape_javascript(micropost.id) %>").html("<%= escape_javascript(render('answers/all_answers')) %>");
and controller action
def more micropost=micropost.find_by(id: params[:id]) @answers=micropost.answers respond_to |format| format.html {redirect_to micropost} format.js end
end
but when press more nothing happens. in console error
nameerror in micropostscontroller#more undefined local variable or method `micropost' #<#:0x007f08be826c48>
micropost defined in controller not showing undefined. why happening?
try changing $(".load-more-<%= escape_javascript(micropost.id) %>")
$(".load-more-<%= @micropost.id %>")
, initializing in controller as
@micropost = micropost.find_by(..)
i'm assuming it's instance variable issue.
Comments
Post a Comment