Skip to content

Instantly share code, notes, and snippets.

@willricketts
Last active December 22, 2015 00:39
Show Gist options
  • Save willricketts/6390774 to your computer and use it in GitHub Desktop.
Save willricketts/6390774 to your computer and use it in GitHub Desktop.
I can't seem to figure out why my Posts index page isn't paging. Halp!
#Gemfile
gem "will_paginate_mongoid"
class PostsController < ApplicationController
before_filter :authenticate_user!, :except => [:show, :index]
def index
Post.paginate :page => params[:page], :per_page => 10
@posts = Post.all.asc(:created_at)
end
def show
@post = Post.find(params[:id])
end
def new
@post = Post.new
end
def create
@post = Post.new(params[:post])
if @post.save
redirect_to posts_path, :notice => "Nice one. Way to roast that poast!"
else
render "new"
end
end
def edit
@post = Post.find(params[:id])
end
def update
@post = Post.find(params[:id])
if @post.update_attributes(params[:post])
redirect_to posts_path, :notice => "Nice one. Way to roast that poast!"
else
render "edit"
end
end
def destroy
@post = Post.find(params[:id])
@post.destroy
redirect_to posts_path, :notice => "That poast is toast!"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment