Note that there are some explanatory texts on larger screens.

plurals
  1. POTrying to use Ajax in Rails for the first time: Controller rendering empty document?
    primarykey
    data
    text
    <p>I have a page rendering a list of <code>Ideas</code>. Each item has a Claim button next to it. What <em>should</em> happen is that the user click the Claim button, <code>Idea#claim</code> controller action runs, and the Claim button goes dim. </p> <p>What <em>actually</em> happens is... nothing. Not even a Rails error page, which is why I'm stuck. Relevant snippets follow:</p> <p><strong>routes.rb</strong></p> <pre><code> resources :ideas do collection do post 'claim' end end </code></pre> <p><strong>ideas_controller#claim</strong></p> <pre><code> def claim @idea = Idea.find(params[:idea_id]) current_user.claim(@idea) respond_to do |format| format.js { render :nothing =&gt; true } end end </code></pre> <p><strong>_idea.html.erb partial</strong></p> <pre><code>&lt;span class="idea-actions" id=&lt;%="idea"+idea.id.to_s%&gt;&gt; &lt;%= link_to "Claim", {method: "post", action: "claim", idea_id: idea.id}, {class: 'claim', remote: true} %&gt; &lt;/span&gt; </code></pre> <p><strong>ideas.js.coffee</strong></p> <pre><code>$ -&gt; $('.claim').bind 'ajax:success', -&gt; alert 'Ajax success!' </code></pre> <p>This is absolutely my first time trying to do something like this, and my CoffeeScript/JS is virtually nonexistent. Any advice or pointers would be greatly appreciated.</p> <p><strong>Edit 1:</strong> Moved code from application.js to ideas.js.coffee, switched form using <code>button_to</code> to <code>link_to</code>. Changes shown in code above. Right now, when I click the link, absolutely nothing happens. Still no joy! :\</p>
    singulars
    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.
    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