jquery - Javascript wont update div rails 4 -


hello rails 4 newbie here. cant seem ajax update view. @ loss. can alert pop when click +1 link in view can't view update (show votes) span id="ajaxed", though database updating. have read rails guides on ajax , @ 6 videos on youtube on how , seems right me doesn't work me. here html:

    <tbody> <% @topics.each |topic| %>   <tr>     <td><%= topic.title %></td>     <td><%= topic.description %></td>     <td><span id="ajaxed"><%=pluralize(topic.votes.count, "vote")%></span></td>     <td><%= link_to "+1",  upvote_topic_path(topic), id: "upvote", remote: true, method: :post%></td>     <td><%= pluralize(topic.downvotes.count, "downvote") %></td>     <td><%= link_to "-1", downvote_topic_path(topic), method: :post %></td>     <td><%= link_to 'show', topic %></td>     <td><%= link_to 'edit', edit_topic_path(topic) %></td>     <td><%= link_to 'destroy', topic, method: :delete, data: { confirm: 'are sure?' } %></td>   </tr> <% end %> 

here controller:

def upvote   @topic = topic.find(params[:id])   @topic.votes.create   #redirect_to topics_path   respond_to |format|     format.html { redirect_to topics_path }     format.js   end end 

here upvote.js.erb:

    $('#ajaxed').text('<%=pluralize(topic.votes.count, "vote")%>'); 

btw other form of javascript or jquery on upvote.js.erb seems work, wont update '#ajaxed' span. tried .html , straight js document.getelementbyid("ajaxed").innerhtml = '<%=pluralize(topic.votes.count, "vote")%>', gives me unwanted results. appreciated. thanks!!!

perhaps need use @topic instead of topic in upvote.js.erb. change $("#ajaxed"). need set dom id specific individual topic.


Comments

Popular posts from this blog

OpenCV OpenCL: Convert Mat to Bitmap in JNI Layer for Android -

android - org.xmlpull.v1.XmlPullParserException: expected: START_TAG {http://schemas.xmlsoap.org/soap/envelope/}Envelope -

python - How to remove the Xframe Options header in django? -