I have a page rendering a list of Ideas. Each item has a Claim button next to it. What should happen is that the user click the Claim button, Idea#claim controller action runs, and the Claim button goes dim.
What actually happens is… nothing. Not even a Rails error page, which is why I’m stuck. Relevant snippets follow:
routes.rb
resources :ideas do
collection do
post 'claim'
end
end
ideas_controller#claim
def claim
@idea = Idea.find(params[:idea_id])
current_user.claim(@idea)
respond_to do |format|
format.js { render :nothing => true }
end
end
_idea.html.erb partial
<span class="idea-actions" id=<%="idea"+idea.id.to_s%>>
<%= link_to "Claim", {method: "post", action: "claim", idea_id: idea.id}, {class: 'claim', remote: true} %>
</span>
ideas.js.coffee
$ ->
$('.claim').bind 'ajax:success', ->
alert 'Ajax success!'
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.
Edit 1: Moved code from application.js to ideas.js.coffee, switched form using button_to to link_to. Changes shown in code above. Right now, when I click the link, absolutely nothing happens. Still no joy! :\
Try to move
remote: truetohtml_optionspart ofbutton_tohttp://api.rubyonrails.org/classes/ActionView/Helpers/UrlHelper.html#method-i-button_to