Note that there are some explanatory texts on larger screens.

plurals
  1. POWhy is Rails app sending two Ajax requests instead of one, only when using Firefox and on my local server?
    primarykey
    data
    text
    <p>I'm learning Rails development and am building a reddit-like app with voting on comments and posts to help learn. I have Ajax-ified the voting, and now on my local machine when I vote a post/comment up or down it sends two requests and creates two votes on either object. These votes are viewable in my votes table. </p> <p>This only occurs in Firefox (not Chrome or IE), and it only occurs on my local machine (it's fine in Heroku). I verified with Firebug that it is sending two requests, but I just can't figure out why. I don't believe my asset pipeline is causing the trouble because there just isn't much in there. </p> <p>This only started once I modified my voting behavior from reloading the page on each vote to using Ajax to display the vote totals. Note that a user can vote as many times as he/she wants right now</p> <p>My code is on github here: <a href="https://github.com/hellomcfly/tl_postit2" rel="nofollow">https://github.com/hellomcfly/tl_postit2</a></p> <p>My app is on Heroku here: <a href="http://fathomless-waters-1981.herokuapp.com" rel="nofollow">http://fathomless-waters-1981.herokuapp.com</a></p> <p>I don't know what code would help, but here is what is in my PostsController:</p> <pre><code>def vote @vote = Vote.create(voteable: @post, user: current_user, vote: params[:vote]) respond_to do |format| format.html do if @vote.vote == false flash[:alert] = "Downvote tallied!" redirect_to :back else flash[:success] = "Upvote tallied!" redirect_to :back end end format.js end end </code></pre> <p>And here is the relevant code in my posts#index template:</p> <pre><code>Net votes: &lt;span id="post_&lt;%=post.id%&gt;_votes"&gt;&lt;%= post.net_votes %&gt;&lt;/span&gt; &lt;ul&gt; &lt;li&gt;&lt;%= link_to "Vote Up", vote_post_path(post, vote: true), method: 'post', remote: true %&gt;&lt;/li&gt; &lt;li&gt;&lt;%= link_to "Vote Down", vote_post_path(post, vote: false), method: 'post', remote: true %&gt;&lt;/li&gt; &lt;/ul&gt; </code></pre> <p>And here is the vote.js.erb code:</p> <pre><code>$("#post_&lt;%= @post.id %&gt;_votes").html(&lt;%= @post.net_votes %&gt;); </code></pre> <p>Thanks for the help.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload