Skip to content

Instantly share code, notes, and snippets.

@fakefarm
Last active December 29, 2015 14:19
Show Gist options
  • Save fakefarm/7683614 to your computer and use it in GitHub Desktop.
Save fakefarm/7683614 to your computer and use it in GitHub Desktop.
Oh ajax...

show.slim

=link_to votes_path(type: 'Mix', id: @mix.id), method: :post, remote: true do

create.js.erb

alert('hi');

votes_controller.rb

def create
  vote = Vote.create(...)
  
  if vote.save
    respond_to do |format|
      format.html { redirect_to :back, notice: 'Thanks for the vote!' }
      format.js
    end
  end
end

Server

  Started POST "/votes?id=38&type=Mix" for 127.0.0.1 at 2013-11-27 14:28:33 -0700
  Processing by VotesController#create as JS
    Parameters: {"id"=>"1"}
    (...Active Record...)
    Rendered votes/create.js.erb within layouts/application (0.2ms)
    (... other files...)
  Completed 200 OK in 25ms (Views: 14.3ms | ActiveRecord: 4.1ms)

Notice, it renders votes/create.js.erb

Problem

The test alert('hi') is not firing and I can't figure out why.

Any guidance?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment