【问题标题】:Thumbs up gem not working appropriately竖起大拇指 gem 无法正常工作
【发布时间】:2013-08-05 05:52:18
【问题描述】:

所以我一直在做这个项目,但是我用于投票系统的竖起大拇指的 gem 不能正常工作。

如果您访问 www.leapfm.com,您会发现出于某种原因,即使是获得 2 票的歌曲也会排在获得 1 票的歌曲之下。这没有任何意义。

现在您可能认为上传日期很重要,但在这种情况下却没有。我上传了一首全新的歌曲并创建了两个帐户两次投票,但它仍然低于歌曲的 1 票。

我该怎么做才能让这个工作正常?

代码

index.html.erb 片段

  <%=link_to image_tag('arrow.gif'), vote_for_song_path(song), :remote => true, :method => :put  if controller.action_name == "index" %>

song_controller.rb 片段

def vote_for
      @song = Song.find(params[:id])
      current_user.vote_for(@song)
      @song.plusminus = @song.votes_for
      @song.save
      respond_to do |format|
        format.js { render 'update_votes' }
      end
  end

  # GET /Songs
  # GET /Songs.json
  def index
    if params[:genre]
      @songs = Song.tagged_with(params[:genre]).paginate(:page => params[:page], :per_page => 15)
      get_last_song
    else      
      @songs = Song.order('plusminus').paginate(:page => params[:page], :per_page => 15)
      get_last_song
    end
  end

宝石HERE

【问题讨论】:

    标签: ruby-on-rails gem ruby-on-rails-4


    【解决方案1】:

    根据您应该尝试的文档:

    @songs=Song.plusminus_tally.order('plusminus_tally DESC').paginate(:page =&gt; params[:page], :per_page =&gt; 15)

    【讨论】:

    • 好吧,这似乎工作,但是,现在分页不起作用?嗯
    • 我们怎样才能让分页也工作?页面底部的更多按钮消失了 www.leapfm.com
    • 我必须更多地了解您的设置。你在用宝石吗?
    • 使用 will_paginate 进行分页,具体请看这里:) stackoverflow.com/questions/18052184/…
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-01-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多