has_many_polymorphs 2.10 → 2.11
Sign up to get free protection for your applications and to get access to all the features.
- data.tar.gz.sig +0 -0
- data/CHANGELOG +2 -0
- data/Manifest +191 -56
- data/TODO +1 -0
- data/examples/hmph.rb +69 -0
- data/generators/commenting/commenting_generator.rb +94 -0
- data/generators/commenting/templates/comment.rb +33 -0
- data/generators/commenting/templates/comment_test.rb +12 -0
- data/generators/commenting/templates/commenting.rb +13 -0
- data/generators/commenting/templates/commenting_extensions.rb +30 -0
- data/generators/commenting/templates/commenting_test.rb +30 -0
- data/generators/commenting/templates/commentings.yml +23 -0
- data/generators/commenting/templates/comments.yml +13 -0
- data/generators/commenting/templates/migration.rb +28 -0
- data/generators/tagging/templates/tagging_extensions.rb +4 -8
- data/has_many_polymorphs.gemspec +19 -12
- data/lib/has_many_polymorphs.rb +3 -4
- data/lib/has_many_polymorphs/autoload.rb +4 -4
- data/lib/has_many_polymorphs/class_methods.rb +8 -8
- data/lib/has_many_polymorphs/debugging_tools.rb +2 -0
- data/lib/has_many_polymorphs/dependencies.rb +9 -4
- data/lib/has_many_polymorphs/support_methods.rb +3 -1
- data/test/fixtures/{aquatic/fish.yml → fish.yml} +0 -0
- data/test/fixtures/{aquatic/little_whale_pupils.yml → little_whale_pupils.yml} +0 -0
- data/test/fixtures/{aquatic/whales.yml → whales.yml} +0 -0
- data/test/integration/app/README +182 -0
- data/test/integration/app/Rakefile +19 -0
- data/test/integration/app/app/controllers/addresses_controller.rb +85 -0
- data/test/integration/app/app/controllers/application.rb +7 -0
- data/test/integration/app/app/controllers/sellers_controller.rb +85 -0
- data/test/integration/app/app/controllers/states_controller.rb +85 -0
- data/test/integration/app/app/controllers/users_controller.rb +85 -0
- data/test/integration/app/app/helpers/addresses_helper.rb +2 -0
- data/test/integration/app/app/helpers/application_helper.rb +3 -0
- data/test/integration/app/app/helpers/sellers_helper.rb +28 -0
- data/test/integration/app/app/helpers/states_helper.rb +2 -0
- data/test/integration/app/app/helpers/users_helper.rb +2 -0
- data/test/integration/app/app/models/address.rb +4 -0
- data/test/integration/app/app/models/citation.rb +3 -0
- data/test/integration/app/app/models/citations_item.rb +4 -0
- data/test/integration/app/app/models/seller.rb +4 -0
- data/test/integration/app/app/models/state.rb +3 -0
- data/test/integration/app/app/models/user.rb +4 -0
- data/test/integration/app/app/views/addresses/edit.html.erb +12 -0
- data/test/integration/app/app/views/addresses/index.html.erb +18 -0
- data/test/integration/app/app/views/addresses/new.html.erb +11 -0
- data/test/integration/app/app/views/addresses/show.html.erb +3 -0
- data/test/integration/app/app/views/layouts/addresses.html.erb +17 -0
- data/test/integration/app/app/views/layouts/sellers.html.erb +17 -0
- data/test/integration/app/app/views/layouts/states.html.erb +17 -0
- data/test/integration/app/app/views/layouts/users.html.erb +17 -0
- data/test/integration/app/app/views/sellers/edit.html.erb +12 -0
- data/test/integration/app/app/views/sellers/index.html.erb +20 -0
- data/test/integration/app/app/views/sellers/new.html.erb +11 -0
- data/test/integration/app/app/views/sellers/show.html.erb +3 -0
- data/test/integration/app/app/views/states/edit.html.erb +12 -0
- data/test/integration/app/app/views/states/index.html.erb +19 -0
- data/test/integration/app/app/views/states/new.html.erb +11 -0
- data/test/integration/app/app/views/states/show.html.erb +3 -0
- data/test/integration/app/app/views/users/edit.html.erb +12 -0
- data/test/integration/app/app/views/users/index.html.erb +22 -0
- data/test/integration/app/app/views/users/new.html.erb +11 -0
- data/test/integration/app/app/views/users/show.html.erb +3 -0
- data/test/integration/app/config/boot.rb +45 -0
- data/test/integration/app/config/database.yml +21 -0
- data/test/integration/app/config/environment.rb +13 -0
- data/test/integration/app/config/environments/development.rb +7 -0
- data/test/integration/app/config/environments/production.rb +18 -0
- data/test/integration/app/config/environments/test.rb +19 -0
- data/test/integration/app/config/locomotive.yml +6 -0
- data/test/integration/app/config/routes.rb +33 -0
- data/test/integration/app/config/ultrasphinx/default.base +56 -0
- data/test/integration/app/config/ultrasphinx/development.conf.canonical +155 -0
- data/test/integration/app/db/migrate/001_create_users.rb +16 -0
- data/test/integration/app/db/migrate/002_create_sellers.rb +14 -0
- data/test/integration/app/db/migrate/003_create_addresses.rb +19 -0
- data/test/integration/app/db/migrate/004_create_states.rb +12 -0
- data/test/integration/app/db/migrate/005_add_capitalization_to_seller.rb +9 -0
- data/test/integration/app/db/migrate/006_add_deleted_to_user.rb +9 -0
- data/test/integration/app/db/migrate/007_add_lat_and_long_to_address.rb +11 -0
- data/test/integration/app/db/migrate/008_create_citations.rb +12 -0
- data/test/integration/app/db/migrate/009_create_citations_items.rb +14 -0
- data/test/integration/app/db/schema.rb +144 -0
- data/test/integration/app/doc/README_FOR_APP +2 -0
- data/test/integration/app/generated_models/aquatic_fish.rb +109 -0
- data/test/integration/app/generated_models/aquatic_pupils_whale.rb +13 -0
- data/test/integration/app/generated_models/aquatic_whale.rb +42 -0
- data/test/integration/app/generated_models/beautiful_fight_relationship.rb +25 -0
- data/test/integration/app/generated_models/citation.rb +40 -0
- data/test/integration/app/generated_models/citations_item.rb +12 -0
- data/test/integration/app/generated_models/dog.rb +183 -0
- data/test/integration/app/generated_models/eaters_foodstuff.rb +13 -0
- data/test/integration/app/generated_models/frog.rb +78 -0
- data/test/integration/app/generated_models/kitten.rb +161 -0
- data/test/integration/app/generated_models/parentship.rb +14 -0
- data/test/integration/app/generated_models/person.rb +53 -0
- data/test/integration/app/generated_models/petfood.rb +125 -0
- data/test/integration/app/generated_models/polymorph_test_some_model.rb +25 -0
- data/test/integration/app/generated_models/seller.rb +30 -0
- data/test/integration/app/generated_models/tabby.rb +26 -0
- data/test/integration/app/generated_models/user.rb +34 -0
- data/test/integration/app/generated_models/wild_boar.rb +87 -0
- data/test/integration/app/generators/commenting_generator_test.rb +83 -0
- data/test/integration/app/public/404.html +30 -0
- data/test/integration/app/public/500.html +30 -0
- data/test/integration/app/public/dispatch.cgi +10 -0
- data/test/integration/app/public/dispatch.fcgi +24 -0
- data/test/integration/app/public/dispatch.rb +10 -0
- data/test/integration/app/public/favicon.ico +0 -0
- data/test/integration/app/public/images/rails.png +0 -0
- data/test/integration/app/public/index.html +277 -0
- data/test/integration/app/public/javascripts/application.js +2 -0
- data/test/integration/app/public/javascripts/controls.js +833 -0
- data/test/integration/app/public/javascripts/dragdrop.js +942 -0
- data/test/integration/app/public/javascripts/effects.js +1088 -0
- data/test/integration/app/public/javascripts/prototype.js +2515 -0
- data/test/integration/app/public/robots.txt +1 -0
- data/test/integration/app/public/stylesheets/scaffold.css +74 -0
- data/test/integration/app/script/about +3 -0
- data/test/integration/app/script/breakpointer +3 -0
- data/test/integration/app/script/console +3 -0
- data/test/integration/app/script/destroy +3 -0
- data/test/integration/app/script/generate +3 -0
- data/test/integration/app/script/performance/benchmarker +3 -0
- data/test/integration/app/script/performance/profiler +3 -0
- data/test/integration/app/script/plugin +3 -0
- data/test/integration/app/script/process/inspector +3 -0
- data/test/integration/app/script/process/reaper +3 -0
- data/test/integration/app/script/process/spawner +3 -0
- data/test/integration/app/script/runner +3 -0
- data/test/integration/app/script/server +3 -0
- data/test/integration/app/test/fixtures/addresses.yml +13 -0
- data/test/integration/app/test/fixtures/citations.yml +9 -0
- data/test/integration/app/test/fixtures/citations_items.yml +9 -0
- data/test/integration/app/test/fixtures/sellers.yml +10 -0
- data/test/integration/app/test/fixtures/states.yml +216 -0
- data/test/integration/app/test/fixtures/users.yml +11 -0
- data/test/integration/app/test/functional/addresses_controller_test.rb +57 -0
- data/test/integration/app/test/functional/sellers_controller_test.rb +57 -0
- data/test/integration/app/test/functional/states_controller_test.rb +57 -0
- data/test/integration/app/test/functional/users_controller_test.rb +57 -0
- data/test/integration/app/test/test_helper.rb +28 -0
- data/test/integration/app/test/unit/address_test.rb +10 -0
- data/test/integration/app/test/unit/citation_test.rb +10 -0
- data/test/integration/app/test/unit/citations_item_test.rb +10 -0
- data/test/integration/app/test/unit/seller_test.rb +10 -0
- data/test/integration/app/test/unit/state_test.rb +10 -0
- data/test/integration/app/test/unit/user_test.rb +10 -0
- data/test/models/aquatic/fish.rb +2 -1
- data/test/models/aquatic/whale.rb +2 -0
- data/test/setup.rb +10 -0
- data/test/test_all.rb +16 -0
- data/test/test_helper.rb +16 -12
- data/test/unit/polymorph_test.rb +35 -34
- metadata +239 -98
- metadata.gz.sig +0 -0
@@ -0,0 +1,12 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../test_helper'
|
2
|
+
|
3
|
+
class CommentTest < Test::Unit::TestCase
|
4
|
+
fixtures :comments, :commentings, <%= commentable_models[0..1].join(", ") -%>
|
5
|
+
|
6
|
+
def test_to_s
|
7
|
+
assert_equal "no1@nowhere.com", <%= model_two -%>.find(2).comments.first.email
|
8
|
+
assert_equal "http://letrails.cn", <%= model_two -%>.find(2).comments.last.url
|
9
|
+
assert_equal "http://fr.ivolo.us", <%= model_two -%>.find(2).comments.first.url
|
10
|
+
end
|
11
|
+
|
12
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
|
2
|
+
# The Commenting join model. This model is automatically generated and added to your app if you run the commenting generator.
|
3
|
+
|
4
|
+
class Commenting < ActiveRecord::Base
|
5
|
+
|
6
|
+
belongs_to :<%= parent_association_name -%><%= ", :foreign_key => \"#{parent_association_name}_id\", :class_name => \"Comment\"" if options[:self_referential] %>
|
7
|
+
belongs_to :commentable, :polymorphic => true
|
8
|
+
|
9
|
+
# This callback makes sure that an orphaned <tt>Comment</tt> is deleted if it no longer tags anything.
|
10
|
+
def before_destroy
|
11
|
+
<%= parent_association_name -%>.destroy_without_callbacks if <%= parent_association_name -%> and <%= parent_association_name -%>.commentings.count == 1
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
class ActiveRecord::Base
|
2
|
+
module CommentingExtensions
|
3
|
+
|
4
|
+
def comment_count
|
5
|
+
commentable?
|
6
|
+
self.comments.size
|
7
|
+
end
|
8
|
+
|
9
|
+
def comment_with(attributes)
|
10
|
+
commentable?(true)
|
11
|
+
begin
|
12
|
+
comment = Comment.create(attributes)
|
13
|
+
raise Comment::Error, "Comment could not be saved with" if comment.new_record?
|
14
|
+
comment.commentables << self
|
15
|
+
rescue
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
private
|
20
|
+
def commentable?(should_raise = false) #:nodoc:
|
21
|
+
unless flag = respond_to?(:<%= parent_association_name -%>s)
|
22
|
+
raise "#{self.class} is not a commentable model" if should_raise
|
23
|
+
end
|
24
|
+
flag
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
include CommentingExtensions
|
29
|
+
end
|
30
|
+
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../test_helper'
|
2
|
+
|
3
|
+
class CommentingTest < Test::Unit::TestCase
|
4
|
+
fixtures :commentings, :comments, <%= commentable_models[0..1].join(", ") -%>
|
5
|
+
|
6
|
+
def setup
|
7
|
+
@obj1 = <%= model_two %>.find(1)
|
8
|
+
@obj2 = <%= model_two %>.find(2)
|
9
|
+
<% if commentable_models.size > 1 -%>
|
10
|
+
@obj3 = <%= model_one -%>.find(1)
|
11
|
+
<% end -%>
|
12
|
+
@comment1 = Comment.find(1)
|
13
|
+
@comment2 = Comment.find(2)
|
14
|
+
@commenting1 = Commenting.find(1)
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_commentable
|
18
|
+
assert_raises(RuntimeError) do
|
19
|
+
@commenting1.send(:commentable?, true)
|
20
|
+
end
|
21
|
+
assert !@commenting1.send(:commentable?)
|
22
|
+
<% if commentable_models.size > 1 -%>
|
23
|
+
assert @obj3.send(:commentable?)
|
24
|
+
<% end -%>
|
25
|
+
<% if options[:self_referential] -%>
|
26
|
+
assert @comment1.send(:commentable?)
|
27
|
+
<% end -%>
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
---
|
2
|
+
<% if commentable_models.size > 1 -%>
|
3
|
+
commentings_003:
|
4
|
+
<%= parent_association_name -%>_id: "2"
|
5
|
+
id: "3"
|
6
|
+
commentable_type: <%= model_one %>
|
7
|
+
commentable_id: "1"
|
8
|
+
<% end -%>
|
9
|
+
commentings_004:
|
10
|
+
<%= parent_association_name -%>_id: "2"
|
11
|
+
id: "4"
|
12
|
+
commentable_type: <%= model_two %>
|
13
|
+
commentable_id: "2"
|
14
|
+
commentings_001:
|
15
|
+
<%= parent_association_name -%>_id: "1"
|
16
|
+
id: "1"
|
17
|
+
commentable_type: <%= model_two %>
|
18
|
+
commentable_id: "1"
|
19
|
+
commentings_002:
|
20
|
+
<%= parent_association_name -%>_id: "1"
|
21
|
+
id: "2"
|
22
|
+
commentable_type: <%= model_two %>
|
23
|
+
commentable_id: "2"
|
@@ -0,0 +1,13 @@
|
|
1
|
+
---
|
2
|
+
comments_001:
|
3
|
+
id: "1"
|
4
|
+
name: frivolous
|
5
|
+
email: no1@nowhere.com
|
6
|
+
url: http://fr.ivolo.us
|
7
|
+
body: this plugin rocks!
|
8
|
+
tags_002:
|
9
|
+
id: "2"
|
10
|
+
name: yuanyiz
|
11
|
+
email: no1@nowhere.com
|
12
|
+
url: http://letrails.cn
|
13
|
+
body: this plugin has saved my life
|
@@ -0,0 +1,28 @@
|
|
1
|
+
|
2
|
+
# A migration to add tables for Comment and Commenting. This file is automatically generated and added to your app if you run the commenting generator.
|
3
|
+
|
4
|
+
class CreateCommentsAndCommentings < ActiveRecord::Migration
|
5
|
+
|
6
|
+
# Add the new tables.
|
7
|
+
def self.up
|
8
|
+
create_table :comments do |t|
|
9
|
+
t.column :name, :string, :null => false
|
10
|
+
t.column :url, :string
|
11
|
+
t.column :email, :string
|
12
|
+
t.column :body, :text
|
13
|
+
end
|
14
|
+
|
15
|
+
create_table :commentings do |t|
|
16
|
+
t.column :<%= parent_association_name -%>_id, :integer, :null => false
|
17
|
+
t.column :commentable_id, :integer, :null => false
|
18
|
+
t.column :commentable_type, :string, :null => false
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
# Remove the tables.
|
23
|
+
def self.down
|
24
|
+
drop_table :comments
|
25
|
+
drop_table :commentings
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
@@ -26,13 +26,13 @@ class ActiveRecord::Base #:nodoc:
|
|
26
26
|
outgoing = tag_cast_to_string(outgoing)
|
27
27
|
<% if options[:self_referential] %>
|
28
28
|
# because of http://dev.rubyonrails.org/ticket/6466
|
29
|
-
taggings.destroy(taggings.find(:all, :include => :<%= parent_association_name -%>).select do |tagging|
|
29
|
+
taggings.destroy(*(taggings.find(:all, :include => :<%= parent_association_name -%>).select do |tagging|
|
30
30
|
outgoing.include? tagging.<%= parent_association_name -%>.name
|
31
|
-
end)
|
31
|
+
end))
|
32
32
|
<% else -%>
|
33
|
-
<%= parent_association_name -%>s.delete(<%= parent_association_name -%>s.select do |tag|
|
33
|
+
<%= parent_association_name -%>s.delete(*(<%= parent_association_name -%>s.select do |tag|
|
34
34
|
outgoing.include? tag.name
|
35
|
-
end)
|
35
|
+
end))
|
36
36
|
<% end -%>
|
37
37
|
end
|
38
38
|
|
@@ -67,10 +67,6 @@ class ActiveRecord::Base #:nodoc:
|
|
67
67
|
#:startdoc:
|
68
68
|
end
|
69
69
|
|
70
|
-
#:stopdoc:
|
71
|
-
alias :<%= parent_association_name -%>s= :tag_with
|
72
|
-
#:startdoc:
|
73
|
-
|
74
70
|
private
|
75
71
|
|
76
72
|
def tag_cast_to_string obj #:nodoc:
|
data/has_many_polymorphs.gemspec
CHANGED
@@ -1,21 +1,28 @@
|
|
1
1
|
|
2
|
-
# Gem::Specification for Has_many_polymorphs-2.
|
2
|
+
# Gem::Specification for Has_many_polymorphs-2.11
|
3
3
|
# Originally generated by Echoe
|
4
4
|
|
5
5
|
Gem::Specification.new do |s|
|
6
6
|
s.name = %q{has_many_polymorphs}
|
7
|
-
s.version = "2.
|
8
|
-
|
9
|
-
s.
|
10
|
-
|
11
|
-
s.
|
12
|
-
s.
|
7
|
+
s.version = "2.11"
|
8
|
+
|
9
|
+
s.specification_version = 2 if s.respond_to? :specification_version=
|
10
|
+
|
11
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
12
|
+
s.authors = [""]
|
13
|
+
s.date = %q{2007-12-04}
|
13
14
|
s.description = %q{An ActiveRecord plugin for self-referential and double-sided polymorphic associations.}
|
15
|
+
s.email = %q{}
|
16
|
+
s.files = ["CHANGELOG", "examples/hmph.rb", "generators/commenting/commenting_generator.rb", "generators/commenting/templates/comment.rb", "generators/commenting/templates/comment_test.rb", "generators/commenting/templates/commenting.rb", "generators/commenting/templates/commenting_extensions.rb", "generators/commenting/templates/commenting_test.rb", "generators/commenting/templates/commentings.yml", "generators/commenting/templates/comments.yml", "generators/commenting/templates/migration.rb", "generators/tagging/tagging_generator.rb", "generators/tagging/templates/migration.rb", "generators/tagging/templates/tag.rb", "generators/tagging/templates/tag_test.rb", "generators/tagging/templates/tagging.rb", "generators/tagging/templates/tagging_extensions.rb", "generators/tagging/templates/tagging_test.rb", "generators/tagging/templates/taggings.yml", "generators/tagging/templates/tags.yml", "init.rb", "lib/has_many_polymorphs/association.rb", "lib/has_many_polymorphs/autoload.rb", "lib/has_many_polymorphs/base.rb", "lib/has_many_polymorphs/class_methods.rb", "lib/has_many_polymorphs/configuration.rb", "lib/has_many_polymorphs/debugging_tools.rb", "lib/has_many_polymorphs/dependencies.rb", "lib/has_many_polymorphs/rake_task_redefine_task.rb", "lib/has_many_polymorphs/reflection.rb", "lib/has_many_polymorphs/support_methods.rb", "lib/has_many_polymorphs.rb", "LICENSE", "Manifest", "README", "test/fixtures/bow_wows.yml", "test/fixtures/cats.yml", "test/fixtures/eaters_foodstuffs.yml", "test/fixtures/fish.yml", "test/fixtures/frogs.yml", "test/fixtures/keep_your_enemies_close.yml", "test/fixtures/little_whale_pupils.yml", "test/fixtures/people.yml", "test/fixtures/petfoods.yml", "test/fixtures/whales.yml", "test/fixtures/wild_boars.yml", "test/integration/app/app/controllers/addresses_controller.rb", "test/integration/app/app/controllers/application.rb", "test/integration/app/app/controllers/sellers_controller.rb", "test/integration/app/app/controllers/states_controller.rb", "test/integration/app/app/controllers/users_controller.rb", "test/integration/app/app/helpers/addresses_helper.rb", "test/integration/app/app/helpers/application_helper.rb", "test/integration/app/app/helpers/sellers_helper.rb", "test/integration/app/app/helpers/states_helper.rb", "test/integration/app/app/helpers/users_helper.rb", "test/integration/app/app/models/address.rb", "test/integration/app/app/models/citation.rb", "test/integration/app/app/models/citations_item.rb", "test/integration/app/app/models/seller.rb", "test/integration/app/app/models/state.rb", "test/integration/app/app/models/user.rb", "test/integration/app/app/views/addresses/edit.html.erb", "test/integration/app/app/views/addresses/index.html.erb", "test/integration/app/app/views/addresses/new.html.erb", "test/integration/app/app/views/addresses/show.html.erb", "test/integration/app/app/views/layouts/addresses.html.erb", "test/integration/app/app/views/layouts/sellers.html.erb", "test/integration/app/app/views/layouts/states.html.erb", "test/integration/app/app/views/layouts/users.html.erb", "test/integration/app/app/views/sellers/edit.html.erb", "test/integration/app/app/views/sellers/index.html.erb", "test/integration/app/app/views/sellers/new.html.erb", "test/integration/app/app/views/sellers/show.html.erb", "test/integration/app/app/views/states/edit.html.erb", "test/integration/app/app/views/states/index.html.erb", "test/integration/app/app/views/states/new.html.erb", "test/integration/app/app/views/states/show.html.erb", "test/integration/app/app/views/users/edit.html.erb", "test/integration/app/app/views/users/index.html.erb", "test/integration/app/app/views/users/new.html.erb", "test/integration/app/app/views/users/show.html.erb", "test/integration/app/config/boot.rb", "test/integration/app/config/database.yml", "test/integration/app/config/environment.rb", "test/integration/app/config/environments/development.rb", "test/integration/app/config/environments/production.rb", "test/integration/app/config/environments/test.rb", "test/integration/app/config/locomotive.yml", "test/integration/app/config/routes.rb", "test/integration/app/config/ultrasphinx/default.base", "test/integration/app/config/ultrasphinx/development.conf.canonical", "test/integration/app/db/migrate/001_create_users.rb", "test/integration/app/db/migrate/002_create_sellers.rb", "test/integration/app/db/migrate/003_create_addresses.rb", "test/integration/app/db/migrate/004_create_states.rb", "test/integration/app/db/migrate/005_add_capitalization_to_seller.rb", "test/integration/app/db/migrate/006_add_deleted_to_user.rb", "test/integration/app/db/migrate/007_add_lat_and_long_to_address.rb", "test/integration/app/db/migrate/008_create_citations.rb", "test/integration/app/db/migrate/009_create_citations_items.rb", "test/integration/app/db/schema.rb", "test/integration/app/doc/README_FOR_APP", "test/integration/app/generated_models/aquatic_fish.rb", "test/integration/app/generated_models/aquatic_pupils_whale.rb", "test/integration/app/generated_models/aquatic_whale.rb", "test/integration/app/generated_models/beautiful_fight_relationship.rb", "test/integration/app/generated_models/citation.rb", "test/integration/app/generated_models/citations_item.rb", "test/integration/app/generated_models/dog.rb", "test/integration/app/generated_models/eaters_foodstuff.rb", "test/integration/app/generated_models/frog.rb", "test/integration/app/generated_models/kitten.rb", "test/integration/app/generated_models/parentship.rb", "test/integration/app/generated_models/person.rb", "test/integration/app/generated_models/petfood.rb", "test/integration/app/generated_models/polymorph_test_some_model.rb", "test/integration/app/generated_models/seller.rb", "test/integration/app/generated_models/tabby.rb", "test/integration/app/generated_models/user.rb", "test/integration/app/generated_models/wild_boar.rb", "test/integration/app/generators/commenting_generator_test.rb", "test/integration/app/public/404.html", "test/integration/app/public/500.html", "test/integration/app/public/dispatch.cgi", "test/integration/app/public/dispatch.fcgi", "test/integration/app/public/dispatch.rb", "test/integration/app/public/favicon.ico", "test/integration/app/public/images/rails.png", "test/integration/app/public/index.html", "test/integration/app/public/javascripts/application.js", "test/integration/app/public/javascripts/controls.js", "test/integration/app/public/javascripts/dragdrop.js", "test/integration/app/public/javascripts/effects.js", "test/integration/app/public/javascripts/prototype.js", "test/integration/app/public/robots.txt", "test/integration/app/public/stylesheets/scaffold.css", "test/integration/app/Rakefile", "test/integration/app/README", "test/integration/app/script/about", "test/integration/app/script/breakpointer", "test/integration/app/script/console", "test/integration/app/script/destroy", "test/integration/app/script/generate", "test/integration/app/script/performance/benchmarker", "test/integration/app/script/performance/profiler", "test/integration/app/script/plugin", "test/integration/app/script/process/inspector", "test/integration/app/script/process/reaper", "test/integration/app/script/process/spawner", "test/integration/app/script/runner", "test/integration/app/script/server", "test/integration/app/test/fixtures/addresses.yml", "test/integration/app/test/fixtures/citations.yml", "test/integration/app/test/fixtures/citations_items.yml", "test/integration/app/test/fixtures/sellers.yml", "test/integration/app/test/fixtures/states.yml", "test/integration/app/test/fixtures/users.yml", "test/integration/app/test/functional/addresses_controller_test.rb", "test/integration/app/test/functional/sellers_controller_test.rb", "test/integration/app/test/functional/states_controller_test.rb", "test/integration/app/test/functional/users_controller_test.rb", "test/integration/app/test/test_helper.rb", "test/integration/app/test/unit/address_test.rb", "test/integration/app/test/unit/citation_test.rb", "test/integration/app/test/unit/citations_item_test.rb", "test/integration/app/test/unit/seller_test.rb", "test/integration/app/test/unit/state_test.rb", "test/integration/app/test/unit/user_test.rb", "test/models/aquatic/fish.rb", "test/models/aquatic/pupils_whale.rb", "test/models/aquatic/whale.rb", "test/models/beautiful_fight_relationship.rb", "test/models/canine.rb", "test/models/cat.rb", "test/models/dog.rb", "test/models/eaters_foodstuff.rb", "test/models/frog.rb", "test/models/kitten.rb", "test/models/parentship.rb", "test/models/person.rb", "test/models/petfood.rb", "test/models/tabby.rb", "test/models/wild_boar.rb", "test/modules/extension_module.rb", "test/modules/other_extension_module.rb", "test/schema.rb", "test/setup.rb", "test/test_all.rb", "test/test_helper.rb", "test/unit/polymorph_test.rb", "TODO", "has_many_polymorphs.gemspec"]
|
14
17
|
s.has_rdoc = true
|
15
|
-
s.
|
16
|
-
s.
|
17
|
-
s.
|
18
|
-
s.
|
18
|
+
s.homepage = %q{http://blog.evanweaver.com/files/doc/fauna/has_many_polymorphs/}
|
19
|
+
s.require_paths = ["lib"]
|
20
|
+
s.rubyforge_project = %q{fauna}
|
21
|
+
s.rubygems_version = %q{0.9.5}
|
22
|
+
s.summary = %q{An ActiveRecord plugin for self-referential and double-sided polymorphic associations.}
|
23
|
+
s.test_files = ["test/test_all.rb"]
|
24
|
+
|
25
|
+
s.add_dependency(%q<activerecord>, [">= 0"])
|
19
26
|
end
|
20
27
|
|
21
28
|
|
@@ -30,7 +37,7 @@ end
|
|
30
37
|
# Echoe.new("has_many_polymorphs") do |p|
|
31
38
|
# p.project = "fauna"
|
32
39
|
# p.summary = "An ActiveRecord plugin for self-referential and double-sided polymorphic associations."
|
33
|
-
# p.url = "http://blog.evanweaver.com/
|
40
|
+
# p.url = "http://blog.evanweaver.com/files/doc/fauna/has_many_polymorphs/"
|
34
41
|
# p.docs_host = "blog.evanweaver.com:~/www/bax/public/files/doc/"
|
35
42
|
# p.dependencies = ["activerecord"]
|
36
43
|
# p.rdoc_pattern = /polymorphs\/association|polymorphs\/class_methods|polymorphs\/reflection|polymorphs\/autoload|polymorphs\/configuration|README|CHANGELOG|TODO|LICENSE|templates\/migration\.rb|templates\/tag\.rb|templates\/tagging\.rb|templates\/tagging_extensions\.rb/
|
data/lib/has_many_polymorphs.rb
CHANGED
@@ -14,16 +14,15 @@ class ActiveRecord::Base
|
|
14
14
|
extend ActiveRecord::Associations::PolymorphicClassMethods
|
15
15
|
end
|
16
16
|
|
17
|
-
if ENV['HMP_DEBUG'] or
|
18
|
-
_logger_warn "has_many_polymorphs: debug mode enabled"
|
17
|
+
if ENV['HMP_DEBUG'] or ENV['RAILS_ENV'] =~ /development|test/ and ENV['USER'] == 'eweaver'
|
19
18
|
require 'has_many_polymorphs/debugging_tools'
|
20
19
|
end
|
21
20
|
|
22
21
|
if defined? Rails and RAILS_ENV and RAILS_ROOT
|
23
|
-
_logger_warn "
|
22
|
+
_logger_warn "rails environment detected"
|
24
23
|
require 'has_many_polymorphs/configuration'
|
25
24
|
require 'has_many_polymorphs/dependencies'
|
26
25
|
require 'has_many_polymorphs/autoload'
|
27
26
|
end
|
28
27
|
|
29
|
-
_logger_debug "
|
28
|
+
_logger_debug "loaded ok"
|
@@ -1,5 +1,5 @@
|
|
1
1
|
|
2
|
-
require 'initializer'
|
2
|
+
require 'initializer' unless defined? Rails::Initializer
|
3
3
|
|
4
4
|
class Rails::Initializer #:nodoc:
|
5
5
|
|
@@ -32,7 +32,7 @@ Note that you can override DEFAULT_OPTIONS via Rails::Configuration#has_many_pol
|
|
32
32
|
def after_initialize_with_autoload
|
33
33
|
after_initialize_without_autoload
|
34
34
|
|
35
|
-
_logger_debug "
|
35
|
+
_logger_debug "autoload hook invoked"
|
36
36
|
|
37
37
|
HasManyPolymorphsAutoload.options[:requirements].each do |requirement|
|
38
38
|
require requirement
|
@@ -44,10 +44,10 @@ Note that you can override DEFAULT_OPTIONS via Rails::Configuration#has_many_pol
|
|
44
44
|
if file.grep(/#{HasManyPolymorphsAutoload.options[:methods].join("|")}/).any?
|
45
45
|
begin
|
46
46
|
model = File.basename(filename)[0..-4].camelize
|
47
|
-
_logger_warn "
|
47
|
+
_logger_warn "preloading parent model #{model}"
|
48
48
|
model.constantize
|
49
49
|
rescue Object => e
|
50
|
-
_logger_warn "
|
50
|
+
_logger_warn "WARNING; possibly critical error preloading #{model}: #{e.inspect}"
|
51
51
|
end
|
52
52
|
end
|
53
53
|
end
|
@@ -208,10 +208,6 @@ The method generates a number of associations aside from the polymorphic one. In
|
|
208
208
|
<tt>:from</tt>:: An array of symbols representing the target models. Required.
|
209
209
|
<tt>:as</tt>:: A symbol for the parent's interface in the join--what the parent 'acts as'.
|
210
210
|
<tt>:through</tt>:: A symbol representing the class of the join model. Follows Rails defaults if not supplied (the parent and the association names, alphabetized, concatenated with an underscore, and singularized).
|
211
|
-
<tt>:foreign_key</tt>:: The column name for the parent's id in the join.
|
212
|
-
<tt>:foreign_type_key</tt>:: The column name for the parent's class name in the join, if the parent itself is polymorphic. Rarely needed.
|
213
|
-
<tt>:polymorphic_key</tt>:: The column name for the child's id in the join.
|
214
|
-
<tt>:polymorphic_type_key</tt>:: The column name for the child's class name in the join.
|
215
211
|
<tt>:dependent</tt>:: Accepts <tt>:destroy</tt>, <tt>:nullify</tt>, <tt>:delete_all</tt>. Controls how the join record gets treated on any associate delete (whether from the polymorph or from an individual collection); defaults to <tt>:destroy</tt>.
|
216
212
|
<tt>:skip_duplicates</tt>:: If <tt>true</tt>, will check to avoid pushing already associated records (but also triggering a database load). Defaults to <tt>true</tt>.
|
217
213
|
<tt>:rename_individual_collections</tt>:: If <tt>true</tt>, all individual collections are prepended with the polymorph name, and the children's parent collection is appended with "_of_#{association_name}"</tt>. For example, <tt>zoos</tt> becomes <tt>zoos_of_animals</tt>. This is to help avoid method name collisions in crowded classes.
|
@@ -227,6 +223,10 @@ The method generates a number of associations aside from the polymorphic one. In
|
|
227
223
|
<tt>:offset</tt>:: An integer. Only affects the polymorphic association.
|
228
224
|
<tt>:namespace</tt>:: A symbol. Prepended to all the models in the <tt>:from</tt> and <tt>:through</tt> keys. This is especially useful for Camping, which namespaces models by default.
|
229
225
|
<tt>:uniq</tt>:: If <tt>true</tt>, the records returned are passed through a pure-Ruby <tt>uniq</tt> before they are returned. Rarely needed.
|
226
|
+
<tt>:foreign_key</tt>:: The column name for the parent's id in the join.
|
227
|
+
<tt>:foreign_type_key</tt>:: The column name for the parent's class name in the join, if the parent itself is polymorphic. Rarely needed--if you're thinking about using this, you almost certainly want to use <tt>acts_as_double_polymorphic_join()</tt> instead.
|
228
|
+
<tt>:polymorphic_key</tt>:: The column name for the child's id in the join.
|
229
|
+
<tt>:polymorphic_type_key</tt>:: The column name for the child's class name in the join.
|
230
230
|
|
231
231
|
If you pass a block, it gets converted to a Proc and added to <tt>:extend</tt>.
|
232
232
|
|
@@ -239,7 +239,7 @@ Be aware, however, that <tt>NULL != 'Spot'</tt> returns <tt>false</tt> due to SQ
|
|
239
239
|
=end
|
240
240
|
|
241
241
|
def has_many_polymorphs (association_id, options = {}, &extension)
|
242
|
-
_logger_debug "
|
242
|
+
_logger_debug "associating #{self}.#{association_id}"
|
243
243
|
reflection = create_has_many_polymorphs_reflection(association_id, options, &extension)
|
244
244
|
# puts "Created reflection #{reflection.inspect}"
|
245
245
|
# configure_dependency_for_has_many(reflection)
|
@@ -384,7 +384,7 @@ Be aware, however, that <tt>NULL != 'Spot'</tt> returns <tt>false</tt> due to SQ
|
|
384
384
|
|
385
385
|
# model caching
|
386
386
|
def inject_dependencies(association_id, reflection)
|
387
|
-
_logger_debug "
|
387
|
+
_logger_debug "injecting dependencies"
|
388
388
|
requirements = [self, reflection.klass].map{|klass| [klass, klass.base_class]}.flatten.uniq
|
389
389
|
(all_classes_for(association_id, reflection) - requirements).each do |target_klass|
|
390
390
|
Dependencies.inject_dependency(target_klass, *requirements)
|
@@ -565,7 +565,7 @@ Be aware, however, that <tt>NULL != 'Spot'</tt> returns <tt>false</tt> due to SQ
|
|
565
565
|
# XXX remove_inappropriate_clauses is not implemented; we'll wait until someone actually needs it
|
566
566
|
return unless string
|
567
567
|
string = string.dup
|
568
|
-
# _logger_debug "
|
568
|
+
# _logger_debug "devolving #{string} for #{klass}"
|
569
569
|
inappropriate_classes = (all_classes_for(association_id, reflection) - # the join class must always be preserved
|
570
570
|
[klass, klass.base_class, reflection.klass, reflection.klass.base_class])
|
571
571
|
inappropriate_classes.map do |klass|
|
@@ -579,7 +579,7 @@ Be aware, however, that <tt>NULL != 'Spot'</tt> returns <tt>false</tt> due to SQ
|
|
579
579
|
# XXX clause removal would go here
|
580
580
|
string.gsub!(quoted_reference, "NULL")
|
581
581
|
end
|
582
|
-
# _logger_debug "
|
582
|
+
# _logger_debug "altered to #{string}"
|
583
583
|
string
|
584
584
|
end
|
585
585
|
|
@@ -31,6 +31,8 @@ Turns on Rails' default dependency logging.
|
|
31
31
|
|
32
32
|
=end
|
33
33
|
|
34
|
+
_logger_warn "debug mode enabled"
|
35
|
+
|
34
36
|
class << ActiveRecord::Base
|
35
37
|
COLLECTION_METHODS = [:belongs_to, :has_many, :has_and_belongs_to_many, :has_one,
|
36
38
|
:has_many_polymorphs, :acts_as_double_polymorphic_join].each do |method_name|
|
@@ -15,18 +15,23 @@ module Dependencies
|
|
15
15
|
target, requirements = target.to_s, requirements.map(&:to_s)
|
16
16
|
injection_graph[target] = ((injection_graph[target] + requirements).uniq - [target])
|
17
17
|
requirements.each {|requirement| mark_for_unload requirement }
|
18
|
-
|
18
|
+
_logger_debug "injection graph: #{injection_graph.inspect}" if Dependencies.log_activity
|
19
19
|
end
|
20
20
|
|
21
21
|
# Make sure any dependent constants of the constants added by <tt>yield</tt> are reloaded.
|
22
22
|
def new_constants_in_with_injection(*descs, &block) # chain
|
23
|
-
|
23
|
+
|
24
|
+
if Dependencies.log_activity
|
25
|
+
_logger_debug "autoloaded constants: #{autoloaded_constants.inspect}"
|
26
|
+
_logger_debug "explicitly unloadable constants: #{explicitly_unloadable_constants.inspect}"
|
27
|
+
end
|
28
|
+
|
24
29
|
returning(new_constants_in_without_injection(*descs, &block)) do |found|
|
25
|
-
|
30
|
+
_logger_debug "new constants: #{found.inspect}" if Dependencies.log_activity and found.any?
|
26
31
|
found.each do |constant|
|
27
32
|
injection_graph[constant].each do |requirement|
|
28
33
|
requirement.constantize
|
29
|
-
|
34
|
+
_logger_debug "constantized #{requirement}" if Dependencies.log_activity
|
30
35
|
end
|
31
36
|
end
|
32
37
|
end
|
@@ -58,15 +58,17 @@ class Object
|
|
58
58
|
|
59
59
|
# Logger shortcut.
|
60
60
|
def _logger_debug s
|
61
|
+
s = "** has_many_polymorphs: #{s}"
|
61
62
|
RAILS_DEFAULT_LOGGER.debug(s) if RAILS_DEFAULT_LOGGER
|
62
63
|
end
|
63
64
|
|
64
65
|
# Logger shortcut.
|
65
66
|
def _logger_warn s
|
67
|
+
s = "** has_many_polymorphs: #{s}"
|
66
68
|
if RAILS_DEFAULT_LOGGER
|
67
69
|
RAILS_DEFAULT_LOGGER.warn(s)
|
68
70
|
else
|
69
|
-
$stderr.puts(
|
71
|
+
$stderr.puts(s)
|
70
72
|
end
|
71
73
|
end
|
72
74
|
|
File without changes
|
File without changes
|
File without changes
|
@@ -0,0 +1,182 @@
|
|
1
|
+
== Welcome to Rails
|
2
|
+
|
3
|
+
Rails is a web-application and persistence framework that includes everything
|
4
|
+
needed to create database-backed web-applications according to the
|
5
|
+
Model-View-Control pattern of separation. This pattern splits the view (also
|
6
|
+
called the presentation) into "dumb" templates that are primarily responsible
|
7
|
+
for inserting pre-built data in between HTML tags. The model contains the
|
8
|
+
"smart" domain objects (such as Account, Product, Person, Post) that holds all
|
9
|
+
the business logic and knows how to persist themselves to a database. The
|
10
|
+
controller handles the incoming requests (such as Save New Account, Update
|
11
|
+
Product, Show Post) by manipulating the model and directing data to the view.
|
12
|
+
|
13
|
+
In Rails, the model is handled by what's called an object-relational mapping
|
14
|
+
layer entitled Active Record. This layer allows you to present the data from
|
15
|
+
database rows as objects and embellish these data objects with business logic
|
16
|
+
methods. You can read more about Active Record in
|
17
|
+
link:files/vendor/rails/activerecord/README.html.
|
18
|
+
|
19
|
+
The controller and view are handled by the Action Pack, which handles both
|
20
|
+
layers by its two parts: Action View and Action Controller. These two layers
|
21
|
+
are bundled in a single package due to their heavy interdependence. This is
|
22
|
+
unlike the relationship between the Active Record and Action Pack that is much
|
23
|
+
more separate. Each of these packages can be used independently outside of
|
24
|
+
Rails. You can read more about Action Pack in
|
25
|
+
link:files/vendor/rails/actionpack/README.html.
|
26
|
+
|
27
|
+
|
28
|
+
== Getting started
|
29
|
+
|
30
|
+
1. At the command prompt, start a new rails application using the rails command
|
31
|
+
and your application name. Ex: rails myapp
|
32
|
+
(If you've downloaded rails in a complete tgz or zip, this step is already done)
|
33
|
+
2. Change directory into myapp and start the web server: <tt>script/server</tt> (run with --help for options)
|
34
|
+
3. Go to http://localhost:3000/ and get "Welcome aboard: You’re riding the Rails!"
|
35
|
+
4. Follow the guidelines to start developing your application
|
36
|
+
|
37
|
+
|
38
|
+
== Web Servers
|
39
|
+
|
40
|
+
By default, Rails will try to use Mongrel and lighttpd if they are installed, otherwise
|
41
|
+
Rails will use the WEBrick, the webserver that ships with Ruby. When you run script/server,
|
42
|
+
Rails will check if Mongrel exists, then lighttpd and finally fall back to WEBrick. This ensures
|
43
|
+
that you can always get up and running quickly.
|
44
|
+
|
45
|
+
Mongrel is a Ruby-based webserver with a C-component (which requires compilation) that is
|
46
|
+
suitable for development and deployment of Rails applications. If you have Ruby Gems installed,
|
47
|
+
getting up and running with mongrel is as easy as: <tt>gem install mongrel</tt>.
|
48
|
+
More info at: http://mongrel.rubyforge.org
|
49
|
+
|
50
|
+
If Mongrel is not installed, Rails will look for lighttpd. It's considerably faster than
|
51
|
+
Mongrel and WEBrick and also suited for production use, but requires additional
|
52
|
+
installation and currently only works well on OS X/Unix (Windows users are encouraged
|
53
|
+
to start with Mongrel). We recommend version 1.4.11 and higher. You can download it from
|
54
|
+
http://www.lighttpd.net.
|
55
|
+
|
56
|
+
And finally, if neither Mongrel or lighttpd are installed, Rails will use the built-in Ruby
|
57
|
+
web server, WEBrick. WEBrick is a small Ruby web server suitable for development, but not
|
58
|
+
for production.
|
59
|
+
|
60
|
+
But of course its also possible to run Rails on any platform that supports FCGI.
|
61
|
+
Apache, LiteSpeed, IIS are just a few. For more information on FCGI,
|
62
|
+
please visit: http://wiki.rubyonrails.com/rails/pages/FastCGI
|
63
|
+
|
64
|
+
|
65
|
+
== Debugging Rails
|
66
|
+
|
67
|
+
Have "tail -f" commands running on the server.log and development.log. Rails will
|
68
|
+
automatically display debugging and runtime information to these files. Debugging
|
69
|
+
info will also be shown in the browser on requests from 127.0.0.1.
|
70
|
+
|
71
|
+
|
72
|
+
== Breakpoints
|
73
|
+
|
74
|
+
Breakpoint support is available through the script/breakpointer client. This
|
75
|
+
means that you can break out of execution at any point in the code, investigate
|
76
|
+
and change the model, AND then resume execution! Example:
|
77
|
+
|
78
|
+
class WeblogController < ActionController::Base
|
79
|
+
def index
|
80
|
+
@posts = Post.find(:all)
|
81
|
+
breakpoint "Breaking out from the list"
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
So the controller will accept the action, run the first line, then present you
|
86
|
+
with a IRB prompt in the breakpointer window. Here you can do things like:
|
87
|
+
|
88
|
+
Executing breakpoint "Breaking out from the list" at .../webrick_server.rb:16 in 'breakpoint'
|
89
|
+
|
90
|
+
>> @posts.inspect
|
91
|
+
=> "[#<Post:0x14a6be8 @attributes={\"title\"=>nil, \"body\"=>nil, \"id\"=>\"1\"}>,
|
92
|
+
#<Post:0x14a6620 @attributes={\"title\"=>\"Rails you know!\", \"body\"=>\"Only ten..\", \"id\"=>\"2\"}>]"
|
93
|
+
>> @posts.first.title = "hello from a breakpoint"
|
94
|
+
=> "hello from a breakpoint"
|
95
|
+
|
96
|
+
...and even better is that you can examine how your runtime objects actually work:
|
97
|
+
|
98
|
+
>> f = @posts.first
|
99
|
+
=> #<Post:0x13630c4 @attributes={"title"=>nil, "body"=>nil, "id"=>"1"}>
|
100
|
+
>> f.
|
101
|
+
Display all 152 possibilities? (y or n)
|
102
|
+
|
103
|
+
Finally, when you're ready to resume execution, you press CTRL-D
|
104
|
+
|
105
|
+
|
106
|
+
== Console
|
107
|
+
|
108
|
+
You can interact with the domain model by starting the console through <tt>script/console</tt>.
|
109
|
+
Here you'll have all parts of the application configured, just like it is when the
|
110
|
+
application is running. You can inspect domain models, change values, and save to the
|
111
|
+
database. Starting the script without arguments will launch it in the development environment.
|
112
|
+
Passing an argument will specify a different environment, like <tt>script/console production</tt>.
|
113
|
+
|
114
|
+
To reload your controllers and models after launching the console run <tt>reload!</tt>
|
115
|
+
|
116
|
+
To reload your controllers and models after launching the console run <tt>reload!</tt>
|
117
|
+
|
118
|
+
|
119
|
+
|
120
|
+
== Description of contents
|
121
|
+
|
122
|
+
app
|
123
|
+
Holds all the code that's specific to this particular application.
|
124
|
+
|
125
|
+
app/controllers
|
126
|
+
Holds controllers that should be named like weblogs_controller.rb for
|
127
|
+
automated URL mapping. All controllers should descend from ApplicationController
|
128
|
+
which itself descends from ActionController::Base.
|
129
|
+
|
130
|
+
app/models
|
131
|
+
Holds models that should be named like post.rb.
|
132
|
+
Most models will descend from ActiveRecord::Base.
|
133
|
+
|
134
|
+
app/views
|
135
|
+
Holds the template files for the view that should be named like
|
136
|
+
weblogs/index.rhtml for the WeblogsController#index action. All views use eRuby
|
137
|
+
syntax.
|
138
|
+
|
139
|
+
app/views/layouts
|
140
|
+
Holds the template files for layouts to be used with views. This models the common
|
141
|
+
header/footer method of wrapping views. In your views, define a layout using the
|
142
|
+
<tt>layout :default</tt> and create a file named default.rhtml. Inside default.rhtml,
|
143
|
+
call <% yield %> to render the view using this layout.
|
144
|
+
|
145
|
+
app/helpers
|
146
|
+
Holds view helpers that should be named like weblogs_helper.rb. These are generated
|
147
|
+
for you automatically when using script/generate for controllers. Helpers can be used to
|
148
|
+
wrap functionality for your views into methods.
|
149
|
+
|
150
|
+
config
|
151
|
+
Configuration files for the Rails environment, the routing map, the database, and other dependencies.
|
152
|
+
|
153
|
+
components
|
154
|
+
Self-contained mini-applications that can bundle together controllers, models, and views.
|
155
|
+
|
156
|
+
db
|
157
|
+
Contains the database schema in schema.rb. db/migrate contains all
|
158
|
+
the sequence of Migrations for your schema.
|
159
|
+
|
160
|
+
doc
|
161
|
+
This directory is where your application documentation will be stored when generated
|
162
|
+
using <tt>rake doc:app</tt>
|
163
|
+
|
164
|
+
lib
|
165
|
+
Application specific libraries. Basically, any kind of custom code that doesn't
|
166
|
+
belong under controllers, models, or helpers. This directory is in the load path.
|
167
|
+
|
168
|
+
public
|
169
|
+
The directory available for the web server. Contains subdirectories for images, stylesheets,
|
170
|
+
and javascripts. Also contains the dispatchers and the default HTML files. This should be
|
171
|
+
set as the DOCUMENT_ROOT of your web server.
|
172
|
+
|
173
|
+
script
|
174
|
+
Helper scripts for automation and generation.
|
175
|
+
|
176
|
+
test
|
177
|
+
Unit and functional tests along with fixtures. When using the script/generate scripts, template
|
178
|
+
test files will be generated for you and placed in this directory.
|
179
|
+
|
180
|
+
vendor
|
181
|
+
External libraries that the application depends on. Also includes the plugins subdirectory.
|
182
|
+
This directory is in the load path.
|