Last active
December 22, 2015 00:39
-
-
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!
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Gemfile | |
gem "will_paginate_mongoid" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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