hmans / schnitzelpress

A lean, mean blogging machine for hackers and fools.
http://schnitzelpress.org
MIT License
77 stars 8 forks source link

Negative page parameter causes Internal Server Error #49

Open ePirat opened 11 years ago

ePirat commented 11 years ago

Specifying a negative value for the page GET parameter on the blog page will cause an internal server error, example: http://schnitzelpress.org/blog/?page=-1

This can be fixed by checking in render_blog in blog.rb:

def render_blog
    total_count   = Post.latest.count
    skipped_count = (params[:page].to_i > 0) ? (params[:page].to_i * 10) : 0
    @posts = Post.latest.skip(skipped_count).limit(10)

    displayed_count = @posts.count(true)
    @show_previous_posts_button = total_count > skipped_count + displayed_count

    render_posts
end