Created
June 24, 2011 12:15
-
-
Save webgago/1044660 to your computer and use it in GitHub Desktop.
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 Post < ActiveRecord::Base | |
end |
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 | |
SECTIONS = %w{seo ruby php java} | |
def index | |
if params[:latest] == true | |
@posts = Post.where("updated_at between now() - interval '7 day' and now()").order("updated_at desc") | |
elsif !params[:section].nil? && SECTIONS.include?(params[:section]) | |
@posts = Post.where("section = #{params[:section]}").order("updated_at desc") | |
else | |
@posts = Post.order("updated_at desc") | |
end | |
@comment_sizes = { } | |
@posts.each do |post| | |
@comment_sizes[post.id] = post.comments.size | |
end | |
end | |
def comments | |
if params[:latest] == true | |
@posts = Post.where("updated_at between now() - interval '7 day' and now()").order("updated_at desc") | |
elsif !params[:section].nil? && SECTIONS.include?(params[:section]) | |
@posts = Post.where("section = #{params[:section]}").order("updated_at desc") | |
else | |
@posts = Post.order("updated_at desc") | |
end | |
@comments = [] | |
@posts.each do |post| | |
@comments += post.comments | |
end | |
end | |
end |
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
Simple::Application.routes.draw do | |
resources :posts do | |
collection do | |
get 'comments' | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment