所以,这是我正在做的一个项目。我终于得到了正确排名的竖起大拇指的宝石。
但是,现在分页不再显示。
编码
song_controller.rb 片段
# 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 %>