class AddEntriesTable < ActiveRecord::Migration
def self.up
create_table :entries do |table|
table.column :title, :string
table.column :content, :text
table.column :created_at, :datetime
end
end
def self.down
drop_table :entries
end
end
def domain_name
[
"www",
("a".."z").to_a.sort_by{rand}.join.slice(0..rand(15)),
%w{com net org}[rand(3)]
].join('.').downcase
end
class AddTaskCount < ActiveRecord::Migration
def seld.up
add_column :projects, :tasks_count, :integer, :default => 0
Project.reset_column_information
Project.find(:all).each do |p|
p.update_attribute :tasks_count, p.tasks.length
end
end
def self.down
remove_column :projects, :tasks_count
end
end
--
class Task < ActiveRecord::Base
belongs_to :project, :counter_cache => true
end
<% if !@object.errors.empty? %>
<div class="errorExplanation" id="errorExplanation">
<ul>
<% for e in @object.errors %>
<li><%= e[1] %></li>
<% end %>
</ul>
</div><br />
<% end %>