Featured asciicasts

openid
Marcin Kulik 12 years ago
parent 305b948576
commit b68e02212d

@ -1,6 +1,7 @@
class HomeController < ApplicationController
def show
@asciicasts = Asciicast.order("created_at DESC").limit(10)
@asciicast = @asciicasts.first
offset = (Asciicast.featured.count * rand).to_i
@asciicast = Asciicast.featured.offset(offset).first || @asciicasts.first
end
end

@ -10,6 +10,8 @@ class Asciicast < ActiveRecord::Base
belongs_to :user
has_many :comments, :order => :created_at, :dependent => :destroy
scope :featured, where(:featured => true)
before_create :assign_user, :unless => :user
attr_accessible :meta, :stdout, :stdout_timing, :stdin, :stdin_timing

@ -0,0 +1,7 @@
class AddFeaturedToAsciicast < ActiveRecord::Migration
def change
add_column :asciicasts, :featured, :boolean, :default => false
add_index :asciicasts, :featured
end
end

@ -11,30 +11,32 @@
#
# It's strongly recommended to check this file into your version control system.
ActiveRecord::Schema.define(:version => 20120311134312) do
ActiveRecord::Schema.define(:version => 20120311142204) do
create_table "asciicasts", :force => true do |t|
t.integer "user_id"
t.string "title"
t.float "duration", :null => false
t.float "duration", :null => false
t.datetime "recorded_at"
t.string "terminal_type"
t.integer "terminal_columns", :null => false
t.integer "terminal_lines", :null => false
t.integer "terminal_columns", :null => false
t.integer "terminal_lines", :null => false
t.string "command"
t.string "shell"
t.string "uname"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
t.string "stdin"
t.string "stdin_timing"
t.string "stdout"
t.string "stdout_timing"
t.string "user_token"
t.text "description"
t.boolean "featured", :default => false
end
add_index "asciicasts", ["created_at"], :name => "index_asciicasts_on_created_at"
add_index "asciicasts", ["featured"], :name => "index_asciicasts_on_featured"
add_index "asciicasts", ["recorded_at"], :name => "index_asciicasts_on_recorded_at"
add_index "asciicasts", ["user_id"], :name => "index_asciicasts_on_user_id"
add_index "asciicasts", ["user_token"], :name => "index_asciicasts_on_user_token"

Loading…
Cancel
Save