thatdankent
thatdankent

Reputation: 950

Upgraded to Rails 3.1 and now my highlight effect does not work

I'm upgrading GiggleTrigger.com to Rails 3.1. The site has a cool highlight effect when users vote on a punchline (an orange flash) - you can try it for yourself if you create an account.

Anyway, when I upgraded to Rails 3.1 the highlight effect no longer works.

Here is my original VotesController (to which I made a minor change, which is noted below):

class VotesController < ApplicationController

  def create
    @punchline = Punchline.find(params[:punchline_id])
    @vote = @punchline.votes.build params[:punchline_id]
    @vote.user = current_user

    respond_to do |format|
      if @vote.save
        format.js
        format.html { redirect_to @punchline }
      else
        format.html { redirect_to root }
      end
    end
  end

Which I changed to (changing :punchline_id to :vote in line 4):

class VotesController < ApplicationController
  def create
    @punchline = Punchline.find(params[:punchline_id])
    @vote = @punchline.votes.build params[:vote]
    @vote.user = current_user

    respond_to do |format|
      if @vote.save
        format.js
        format.html { redirect_to @punchline }
      else
        format.html { redirect_to root }
      end
    end
  end

The view looks like this:

    <span id="vote_total_<%= punchline.id %>" class="punchline_votes">
        <%= punchline.votes.size %>
    </span>
<span id="vote_button">
       <%= button_to 'giggle', punchline_votes_path(:punchline_id => punchline), 
                                                    :remote => true %>
</span>

This is the ajax (placed in the views/votes file as create.js.rjs):

page.replace_html "vote_total_#{@punchline.id}", "#{@punchline.votes.size}"
page["vote_total_#{@punchline.id}"].effect :highlight, 
                                           :color => "#f7931e", 
                                           :endcolor => "#e6e6e6"

The vote button (called "giggle" ) was not creating a vote until I changed :punchline_id to :vote. But it still is not giving me the flash effect. My thought is that maybe I need to somehow get this javascript into the asset pipeline. Any guidance would be appreciated. Thanks.

Upvotes: 1

Views: 284

Answers (1)

grumpit
grumpit

Reputation: 187

Off the top, this is likely because highlight is a Prototype function and Rails 3.1 uses jQuery by default.

Upvotes: 2

Related Questions