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
#! /bin/sh | |
### BEGIN INIT INFO | |
# | |
# Source https://raw.github.com/jnstq/rails-nginx-passenger-ubuntu/master/nginx/nginx | |
# | |
# Provides: nginx | |
# Required-Start: $remote_fs $syslog | |
# Required-Stop: $remote_fs $syslog | |
# Default-Start: 2 3 4 5 | |
# Default-Stop: 0 1 6 |
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
# posts_controller.rb | |
def index | |
@published_posts = Post.all :conditions => {['published_at <= ?', Time.now]} | |
@unpublished_posts = Post.all :conditions => {['published_at IS NULL OR published_at > ?', Time.now]} | |
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
# posts_controller.rb | |
def index | |
@published_posts = Post.all_published | |
@unpublished_posts = Post.all_unpublished | |
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
# Post.rb | |
def self.all_published | |
all :conditions => {['published_at <= ?', Time.now]} | |
end | |
def self.all_unpublished | |
all :conditions => {['published_at IS NULL OR published_at > ?', Time.now]} | |
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
# /app/controllers/posts_controller.rb | |
class PostController < ApplicationController | |
def repost | |
post = Post.find(params[:id]) | |
if post.user == current_user | |
flash[:notice] = "Sorry, you can't repost your own posts" | |
elsif post.reposts.where(:user_id => current_user.id).present? | |
flash[:notice] = "You already reposted!" | |
else | |
# ... |
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
# /app/controllers/posts_controller.rb | |
class PostsController < ApplicationController | |
def repost | |
post = Post.find(params[:id]) | |
flash[:notice] = post.repost_by(current_user) | |
redirect_to post | |
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
# /app/models/post.rb | |
class Post< ActiveRecord::Base | |
def repost_by(repost) | |
if self.user == retweeter | |
"Sorry, you can't retpost your own posts" | |
elsif | |
self.retposts.where(:user_id => repost.id).present? "You already reposted!" | |
else | |
# ... | |
"Succesfully reposted" |
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
# /app/controllers/posts_controller.rb | |
def index | |
@posts = Post.find( | |
:all, | |
:conditions => {:user_id => current_user.id}, :order => 'created_at desc', | |
:limit => 10 | |
) | |
@trending = Topic.find( | |
 :all, | |
:conditions => ["started_trending > ?", 1.day.ago], |
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
# /app/controllers/posts_controller.rb | |
def index | |
@posts = Post.where(:user_id => current_user.id). | |
order('created_at desc'). | |
limit(10) | |
@trending = Topic.where('started_trending > ?', 1.day.ago). | |
order('mentions desc'). | |
limit(7) | |
# ... |
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
# /app/controllers/posts_controller.rb | |
def index | |
@posts = current_user.posts. | |
order('created_at desc'). | |
limit(10) | |
#... | |
end |
OlderNewer