I’ve spent the last few hours finding out why will_paginate wouldn’t work on my user account area page “site.com/” (users/new) but would work on other pages such as site.com/search, site.com/browse.
Is there any way to deal with my current issue? The user account area page is the same page the user signs up on but with the signup content hidden. It is my root path (site.com/).
The next and previous links show but all results are displayed on one page.
Controller:
class UsersController < ApplicationController
include UsersHelper
include MessagesHelper
def new
@user = User.new
if logged_in?
@current_user = User.find_by_username(current_user.username)
@default_photo = Photo.find(current_user.profile.photo_id) if current_user.profile.photo_id
@micropost = Micropost.new(:user_id => users_id)
@microposts = current_user.microposts.page(params[:page]).per_page(1)
@default_image = default_profile_image
@comment = Comment.new(:user_id => current_user.id)
HTML/HAML:
.microposts
= render 'users/partials/micropost_form'
- if @current_user.microposts.any?
= render 'users/partials/microposts'
= will_paginate @microposts
Some of my microposts partial
<% @current_user.microposts.each do |m| %>
<% if m.poster_id.nil? %>
<div class="postHolder">
<nav class="micropostOptions">
<ul class="postMenu">
<li class="deletePost"><%= link_to content_tag(:span, "Delete post"), m, :method => :delete, :confirm => "Are you sure?", :title => m.content, :class => "message_delete" %>
</li>
<li class="disableCommenting"><%= link_to content_tag(:span, "Pause commenting"), "2" %></li>
<li class="blockCommenter"><%= link_to content_tag(:span, "Block commenter"), "3" %></li>
<li class="openInNewWindow"><%= link_to content_tag(:span, "Open in new window"), "4" %></li>
<li class="reportAbuse"><%= link_to content_tag(:span, "Report abuse"), "5" %></li>
</ul>
</nav>
Update
Hmm, I just created a separate action in my users controller called microposts gave it its own route and view then tried will_paginate on that page but it still returns all results on one page. Confused
Fixed thanks to Jeremy’s comment above. I changed my partial so that it would refer to @microposts instead of @current_user.microposts and my problem was solved. Don’t know how I could miss that.