Skip to content

Instantly share code, notes, and snippets.

commit 3696e5b00494629b2304221529c079d64a299888
Author: Rida <rida@spinbits.com>
Date: Tue Oct 28 01:33:06 2008 +0400
Finishing the Arabic locale
@rbarazi
rbarazi / .gitignore
Created January 26, 2010 18:03
[Beginning Rails 3] Listing AppD-1 – The .gitignore file content in our working copy root
.bundle
config/database.yml
log/*.log
db/*.sqlite3
tmp/**/*
@rbarazi
rbarazi / salutation_controller.rb
Created March 2, 2010 20:13
[Beginning Rails 3] Listing 2-2. The updated app/controllers/salutation_controller.rb File
class SalutationController < ApplicationController
def hello
@message = 'Hello World!'
end
end
@rbarazi
rbarazi / hello.html.erb
Created March 2, 2010 20:36
[Beginning Rails 3] Listing 2-3. The app/views/salutation/hello.html.erb File
<html>
<body>
<h1><%= @message %></h1>
</body>
</html>
@rbarazi
rbarazi / routes.rb
Created March 2, 2010 20:54
[Beginning Rails 3] Listing 2-4. The config/routes.rb file
Hello::Application.routes.draw do |map|
match ':controller(/:action(/:id(.:format)))'
end
@rbarazi
rbarazi / comment.rb
Created March 8, 2010 21:45
[Beginning Rails 3] Listing 5-16. The Comment model in app/models/comment.rb
class Comment < ActiveRecord::Base
belongs_to :article
end
@rbarazi
rbarazi / article.rb
Created March 8, 2010 21:47
[Beginning Rails 3] Listing 5-17. The Article model in app/models/article.rb
class Article < ActiveRecord::Base
validates :title, :presence => true
validates :body, :presence => true
belongs_to :user
has_and_belongs_to_many :categories
has_many :comments
def long_title
"#{title} - #{published_at}"
@rbarazi
rbarazi / user.rb
Created March 8, 2010 21:56
[Beginning Rails 3] Listing 5-18. The has_many :through declarations in app/models/user.rb
class User < ActiveRecord::Base
has_one :profile
has_many :articles, :order => 'published_at DESC, title ASC',
:dependent => :nullify
has_many :replies, :through => :articles, :source => :comments
end
@rbarazi
rbarazi / category.rb
Created March 8, 2010 23:32
[Beginning Rails 3] Listing 5-19. defaut_scope declaration in app/models/category.rb
class Category < ActiveRecord::Base
has_and_belongs_to_many :articles
default_scope order('categories.name')
end
@rbarazi
rbarazi / article.rb
Created March 8, 2010 23:42
[Beginning Rail 3] Listing 5-20. Named scopes declarations in app/models/article.rb
class Article < ActiveRecord::Base
validates :title, :presence => true
validates :body, :presence => true
belongs_to :user
has_and_belongs_to_many :categories
has_many :comments
scope :published, where("articles.published_at IS NOT NULL")
scope :draft, where("articles.published_at IS NULL")