所以,这是我正在研究的项目。我终于得到了thumbs up宝石来正确排名。
然而,现在paginate不再显示。
代码
song_controller.rb snippit
# 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)
@songs = Song.plusminus_tally.order('plusminus_tally DESC').paginate(:page => params[:page], :per_page => 15)
get_last_song
end
end
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
index.html.erb
<div id="song_list">
<%= render @songs %>
</div>
</div>
<div class="pagination-centered">
<ul class="pagination">
<div class="prev">
<% if @songs.previous_page %>
<%= link_to "Back", params.merge(page: @songs.previous_page) %>
<% end %>
</div>
<div class="next">
<% if @songs.next_page %>
<%= link_to "More", params.merge(page: @songs.next_page) %>
<% end %>
答案 0 :(得分:0)
查看这个github主题:https://github.com/bouchard/thumbs_up/issues/64
您也可以从代码中删除此行:
@songs = Song.order('plusminus').paginate(:page => params[:page], :per_page => 15)
答案 1 :(得分:0)
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 desc nulls last').paginate(:page => params[:page], :per_page => 15)
get_last_song
end
end