almanac 0.4.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (127) hide show
  1. data/MIT-LICENSE +20 -0
  2. data/README.md +76 -0
  3. data/Rakefile +40 -0
  4. data/app/assets/images/almanac/background.jpg +0 -0
  5. data/app/assets/images/almanac/icons/compose.png +0 -0
  6. data/app/assets/images/almanac/icons/feed.png +0 -0
  7. data/app/assets/images/almanac/icons/gear.png +0 -0
  8. data/app/assets/images/almanac/icons/glyphicons-halflings-white.png +0 -0
  9. data/app/assets/images/almanac/icons/glyphicons-halflings.png +0 -0
  10. data/app/assets/images/almanac/icons/upload.png +0 -0
  11. data/app/assets/images/almanac/logo.jpg +0 -0
  12. data/app/assets/javascripts/almanac/2-jquery.backstretch.js +357 -0
  13. data/app/assets/javascripts/almanac/3-pixastic.js +637 -0
  14. data/app/assets/javascripts/almanac/4-bootstrap-datepicker.js +454 -0
  15. data/app/assets/javascripts/almanac/5-main.coffee.erb +46 -0
  16. data/app/assets/javascripts/almanac/application.js +16 -0
  17. data/app/assets/stylesheets/almanac/1-datepicker.css +7 -0
  18. data/app/assets/stylesheets/almanac/2-main.css.scss +279 -0
  19. data/app/assets/stylesheets/almanac/application.css +15 -0
  20. data/app/controllers/almanac/application_controller.rb +24 -0
  21. data/app/controllers/almanac/blogs_controller.rb +64 -0
  22. data/app/controllers/almanac/comments_controller.rb +41 -0
  23. data/app/controllers/almanac/images_controller.rb +29 -0
  24. data/app/controllers/almanac/posts_controller.rb +109 -0
  25. data/app/helpers/almanac/application_helper.rb +4 -0
  26. data/app/models/almanac/blog.rb +32 -0
  27. data/app/models/almanac/comment.rb +20 -0
  28. data/app/models/almanac/image.rb +10 -0
  29. data/app/models/almanac/post.rb +55 -0
  30. data/app/views/almanac/blogs/_form.html.haml +76 -0
  31. data/app/views/almanac/blogs/_topbar.html.haml +5 -0
  32. data/app/views/almanac/blogs/edit.html.haml +4 -0
  33. data/app/views/almanac/blogs/new.html.haml +3 -0
  34. data/app/views/almanac/blogs/spam.html.haml +15 -0
  35. data/app/views/almanac/posts/_form.html.haml +52 -0
  36. data/app/views/almanac/posts/_post.html.haml +59 -0
  37. data/app/views/almanac/posts/edit.html.haml +1 -0
  38. data/app/views/almanac/posts/index.html.haml +30 -0
  39. data/app/views/almanac/posts/index.rss.builder +18 -0
  40. data/app/views/almanac/posts/new.html.haml +1 -0
  41. data/app/views/almanac/posts/show.html.haml +4 -0
  42. data/app/views/almanac/posts/tag.html.haml +22 -0
  43. data/app/views/layouts/almanac/_ga.html.haml +10 -0
  44. data/app/views/layouts/almanac/_twitter_follow.html.haml +2 -0
  45. data/app/views/layouts/almanac/application.html.haml +52 -0
  46. data/config/routes.rb +22 -0
  47. data/db/migrate/20121009222451_create_almanac_posts.rb +17 -0
  48. data/db/migrate/20121010033555_create_almanac_blogs.rb +14 -0
  49. data/db/migrate/20121017032059_add_excerpt_to_almanac_posts.rb +11 -0
  50. data/db/migrate/20121017210007_create_almanac_files.rb +15 -0
  51. data/db/migrate/20121017221819_rename_file_to_image.rb +9 -0
  52. data/db/migrate/20121025223403_add_image_fields_to_almanac_blogs.rb +13 -0
  53. data/db/migrate/20121029211221_add_new_fields_to_blogs.rb +15 -0
  54. data/db/migrate/20121029221815_acts_as_taggable_on_migration.rb +30 -0
  55. data/db/migrate/20121101030836_create_almanac_comments.rb +16 -0
  56. data/db/migrate/20121102181941_add_rakismet_fields_to_blogs.rb +13 -0
  57. data/db/migrate/20121102185130_add_spam_to_comments.rb +11 -0
  58. data/db/migrate/20121110000024_add_written_at_to_posts.rb +11 -0
  59. data/db/migrate/20121112205256_add_background_fields_to_blogs.rb +13 -0
  60. data/db/migrate/20121113010557_add_footer_to_almanac_blogs.rb +11 -0
  61. data/db/migrate/20121114043648_change_default_value_for_background_tiles_in_almanac_blogs.rb +9 -0
  62. data/lib/almanac.rb +16 -0
  63. data/lib/almanac/MarkdownParser.rb +18 -0
  64. data/lib/almanac/engine.rb +9 -0
  65. data/lib/almanac/version.rb +3 -0
  66. data/lib/tasks/almanac_tasks.rake +4 -0
  67. data/spec/controllers/blogs_controller_spec.rb +80 -0
  68. data/spec/controllers/comments_controller_spec.rb +51 -0
  69. data/spec/controllers/posts_controller_spec.rb +120 -0
  70. data/spec/dummy/README.rdoc +261 -0
  71. data/spec/dummy/Rakefile +7 -0
  72. data/spec/dummy/app/assets/javascripts/application.js +15 -0
  73. data/spec/dummy/app/assets/stylesheets/application.css +13 -0
  74. data/spec/dummy/app/controllers/application_controller.rb +3 -0
  75. data/spec/dummy/app/helpers/application_helper.rb +2 -0
  76. data/spec/dummy/app/models/ability.rb +13 -0
  77. data/spec/dummy/app/models/user.rb +11 -0
  78. data/spec/dummy/app/views/layouts/application.html.erb +14 -0
  79. data/spec/dummy/config.ru +4 -0
  80. data/spec/dummy/config/application.rb +59 -0
  81. data/spec/dummy/config/boot.rb +10 -0
  82. data/spec/dummy/config/database.yml +25 -0
  83. data/spec/dummy/config/environment.rb +5 -0
  84. data/spec/dummy/config/environments/development.rb +37 -0
  85. data/spec/dummy/config/environments/production.rb +67 -0
  86. data/spec/dummy/config/environments/test.rb +37 -0
  87. data/spec/dummy/config/initializers/almanac.rb +1 -0
  88. data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
  89. data/spec/dummy/config/initializers/devise.rb +233 -0
  90. data/spec/dummy/config/initializers/dragonfly.rb +7 -0
  91. data/spec/dummy/config/initializers/inflections.rb +15 -0
  92. data/spec/dummy/config/initializers/mime_types.rb +5 -0
  93. data/spec/dummy/config/initializers/secret_token.rb +7 -0
  94. data/spec/dummy/config/initializers/session_store.rb +8 -0
  95. data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
  96. data/spec/dummy/config/locales/en.yml +5 -0
  97. data/spec/dummy/config/routes.rb +14 -0
  98. data/spec/dummy/db/migrate/20121009230705_create_almanac_posts.rb +18 -0
  99. data/spec/dummy/db/migrate/20121010033827_create_almanac_blogs.rb +15 -0
  100. data/spec/dummy/db/migrate/20121102224650_add_excerpt_to_almanac_posts.rb +12 -0
  101. data/spec/dummy/db/migrate/20121102224651_create_almanac_files..rb +16 -0
  102. data/spec/dummy/db/migrate/20121102224652_rename_file_to_image.rb +10 -0
  103. data/spec/dummy/db/migrate/20121102224653_add_image_fields_to_almanac_blogs.rb +14 -0
  104. data/spec/dummy/db/migrate/20121102224654_add_new_fields_to_almanac_blogs.rb +16 -0
  105. data/spec/dummy/db/migrate/20121102224655_acts_as_taggable_on_migration.rb +31 -0
  106. data/spec/dummy/db/migrate/20121102224656_create_almanac_comments.rb +17 -0
  107. data/spec/dummy/db/migrate/20121102224657_add_rakismet_fields_to_almanac_blogs.rb +14 -0
  108. data/spec/dummy/db/migrate/20121102224658_add_spam_to_almanac_comments.rb +12 -0
  109. data/spec/dummy/db/migrate/20121106220325_devise_create_users.rb +46 -0
  110. data/spec/dummy/db/migrate/20121114032144_add_written_at_to_almanac_posts.rb +12 -0
  111. data/spec/dummy/db/migrate/20121114032145_add_background_fields_to_almanac_blogs.rb +14 -0
  112. data/spec/dummy/db/migrate/20121114032146_add_footer_to_almanac_blogs.rb +12 -0
  113. data/spec/dummy/db/schema.rb +98 -0
  114. data/spec/dummy/db/test.sqlite3 +0 -0
  115. data/spec/dummy/log/production.log +1 -0
  116. data/spec/dummy/log/test.log +2930 -0
  117. data/spec/dummy/public/404.html +26 -0
  118. data/spec/dummy/public/422.html +26 -0
  119. data/spec/dummy/public/500.html +25 -0
  120. data/spec/dummy/public/favicon.ico +0 -0
  121. data/spec/dummy/script/rails +6 -0
  122. data/spec/factories.rb +72 -0
  123. data/spec/models/blog_spec.rb +16 -0
  124. data/spec/models/comment_spec.rb +35 -0
  125. data/spec/models/post_spec.rb +79 -0
  126. data/spec/spec_helper.rb +37 -0
  127. metadata +485 -0
@@ -0,0 +1,11 @@
1
+ class AddFooterToAlmanacBlogs < ActiveRecord::Migration
2
+ def up
3
+ change_table :almanac_blogs do |t|
4
+ t.text :footer
5
+ end
6
+ end
7
+
8
+ def down
9
+ remove_column :almanac_blogs, :footer
10
+ end
11
+ end
@@ -0,0 +1,9 @@
1
+ class ChangeDefaultValueForBackgroundTilesInAlmanacBlogs < ActiveRecord::Migration
2
+ def self.up
3
+ change_column :almanac_blogs, :background_tile, :boolean, :default => true
4
+ end
5
+
6
+ def self.down
7
+
8
+ end
9
+ end
@@ -0,0 +1,16 @@
1
+ require "almanac/engine"
2
+ require "devise"
3
+ require "cancan"
4
+ require "haml"
5
+ require "jquery-rails"
6
+ require "kramdown"
7
+ require "will_paginate"
8
+ require "will_paginate-bootstrap"
9
+ require "acts-as-taggable-on"
10
+ require "almanac/MarkdownParser"
11
+ require "rakismet"
12
+ require "bootstrap-rails-engine"
13
+
14
+ module Almanac
15
+ mattr_accessor :user_class
16
+ end
@@ -0,0 +1,18 @@
1
+ class MarkdownParser
2
+ def initialize(*args)
3
+ @attribute = *args[0]
4
+ end
5
+
6
+ def before_save(record)
7
+ markdown = Kramdown::Document.new(record.send("#{@attribute}")).to_html
8
+ record.send("#{@attribute}=", markdown)
9
+ end
10
+
11
+ def html_to_markdown(text)
12
+ Kramdown::Document.new(text.html_safe, :input => 'html').to_kramdown
13
+ end
14
+
15
+ def markdown_to_html(text)
16
+ Kramdown::Document.new(text.html_safe, :input => 'kramdown').to_html
17
+ end
18
+ end
@@ -0,0 +1,9 @@
1
+ module Almanac
2
+ class Engine < ::Rails::Engine
3
+ isolate_namespace Almanac
4
+
5
+ config.generators do |g|
6
+ g.test_framework :rspec, :view_specs => false
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,3 @@
1
+ module Almanac
2
+ VERSION = "0.4.4"
3
+ end
@@ -0,0 +1,4 @@
1
+ # desc "Explaining what the task does"
2
+ # task :almanac do
3
+ # # Task goes here
4
+ # end
@@ -0,0 +1,80 @@
1
+ require 'spec_helper'
2
+
3
+ describe Almanac::BlogsController do
4
+ describe "POST create" do
5
+ context "with valid attributes" do
6
+ it "creates a new blog" do
7
+ expect{
8
+ post :create, :use_route => :almanac, blog: attributes_for(:blog, :author_id => nil)
9
+ }.to change(Almanac::Blog, :count).by(1)
10
+
11
+ end
12
+
13
+ it "redirects to the site root" do
14
+ post :create, :use_route => :almanac, blog: attributes_for(:blog, :author_id => nil)
15
+ response.should redirect_to root_url
16
+ end
17
+ end
18
+ context "with invalid attributes" do
19
+ it "doesn't create a new blog" do
20
+ expect{
21
+ post :create, :use_route => :almanac, blog: attributes_for(:blog, :title => nil, :author_id => nil)
22
+ }.to_not change(Almanac::Blog, :count)
23
+
24
+ end
25
+
26
+ it "re-renders the new method" do
27
+ post :create, :use_route => :almanac, blog: attributes_for(:blog, :title => nil, :author_id => nil)
28
+ response.should render_template :new
29
+ end
30
+ end
31
+ end
32
+
33
+ describe "PUT update" do
34
+ before :each do
35
+ @blog = create(:blog)
36
+ end
37
+ context "with valid attributes" do
38
+ it "changes blog's attributes" do
39
+ put :update, id: @blog.id, :use_route => :almanac,
40
+ blog: attributes_for(:blog, title: "Testz")
41
+ @blog.reload
42
+ @blog.title.should eq("Testz")
43
+ end
44
+ it "redirects to the site root" do
45
+ put :update, :use_route => :almanac, id: @blog.id, blog: attributes_for(:blog)
46
+ response.should redirect_to root_url
47
+ end
48
+ end
49
+ context "with invalid attributes" do
50
+ it "doesn't change blog's attributes" do
51
+ old_title = @blog.title
52
+ put :update, id: @blog.id, :use_route => :almanac,
53
+ blog: attributes_for(:blog, title: nil)
54
+ @blog.reload
55
+ @blog.title.should eq(old_title)
56
+ end
57
+ it "re-renders the edit method" do
58
+ put :update, id: @blog.id, :use_route => :almanac,
59
+ blog: attributes_for(:blog, title: nil)
60
+ response.should render_template :edit
61
+ end
62
+ end
63
+ end
64
+
65
+ describe "GET spam" do
66
+ before :each do
67
+ @blog = create(:blog)
68
+ post = create(:post_with_comments, comments_count: 10, blog_id: @blog.id)
69
+ @spam_comments = create_list(:spam_comment, 5, post_id: post.id)
70
+ end
71
+ it "returns spam comments" do
72
+ get :spam, :use_route => :almanac, id: @blog.id
73
+ assigns(:comments).should eq(@spam_comments)
74
+ end
75
+ it "renders the spam page" do
76
+ get :spam, :use_route => :almanac, id: @blog.id
77
+ response.should render_template :spam
78
+ end
79
+ end
80
+ end
@@ -0,0 +1,51 @@
1
+ require 'spec_helper'
2
+
3
+ describe Almanac::CommentsController do
4
+ before :each do
5
+ @post = create(:post)
6
+ end
7
+
8
+ describe "POST create" do
9
+ context "with valid attributes" do
10
+ it "creates a new comment" do
11
+ expect{
12
+ post :create, :use_route => :almanac, comment: attributes_for(:comment), :post_id => @post.id
13
+ }.to change(Almanac::Comment, :count).by(1)
14
+ end
15
+
16
+ it "redirects to the post" do
17
+ post :create, :use_route => :almanac, comment: attributes_for(:comment), :post_id => @post.id
18
+ response.should redirect_to @post
19
+ end
20
+ end
21
+ context "with invalid attributes" do
22
+ it "doesn't create a new comment" do
23
+ expect{
24
+ post :create, :use_route => :almanac, comment: attributes_for(:comment, :body => nil), :post_id => @post.id
25
+ }.to_not change(Almanac::Comment, :count)
26
+ end
27
+
28
+ it "redirects to the post" do
29
+ post :create, :use_route => :almanac, comment: attributes_for(:comment), :post_id => @post.id
30
+ response.should redirect_to @post
31
+ end
32
+ end
33
+ end
34
+
35
+ describe "DELETE destroy" do
36
+ before :each do
37
+ @comment = create(:comment, :post_id => @post.id)
38
+ end
39
+
40
+ it "deletes the comment" do
41
+ expect{
42
+ delete :destroy, :use_route => :almanac, id: @comment.id, :post_id => @post.id
43
+ }.to change(Almanac::Comment, :count).by(-1)
44
+ end
45
+
46
+ it "redirects to the post" do
47
+ delete :destroy, :use_route => :almanac, id: @comment.id, :post_id => @post.id
48
+ response.should redirect_to @post
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,120 @@
1
+ require 'spec_helper'
2
+
3
+ describe Almanac::PostsController do
4
+ before :each do
5
+ @blog = create(:blog)
6
+ end
7
+
8
+ describe "GET index" do
9
+ it "populates an array of posts" do
10
+ posts_count = 5
11
+ posts = create_list(:post, posts_count, blog_id: @blog.id)
12
+ get :index, :use_route => :almanac
13
+ assigns(:posts).should eq posts.reverse
14
+ end
15
+
16
+ it "populates an array of drafts" do
17
+ drafts_count = 3
18
+ drafts = create_list(:post_draft, drafts_count, blog_id: @blog.id)
19
+ get :index, :use_route => :almanac
20
+ assigns(:drafts).should eq drafts.reverse
21
+ end
22
+
23
+ it "renders the :index view" do
24
+ get :index, :use_route => :almanac
25
+ response.should render_template :index
26
+ end
27
+ end
28
+
29
+ describe "GET tag" do
30
+ it "populates an array of tagged posts" do
31
+ posts_count = 5
32
+ posts = create_list(:post, posts_count, blog_id: @blog.id)
33
+ get :tag, :use_route => :almanac, :tag_name => "common"
34
+ assigns(:posts).should eq posts.reverse
35
+ end
36
+
37
+ it "renders the :tag view" do
38
+ get :tag, :use_route => :almanac
39
+ response.should render_template :tag
40
+ end
41
+ end
42
+
43
+ describe "POST create" do
44
+ context "with valid attributes" do
45
+ it "creates a new post" do
46
+ expect{
47
+ post :create, :use_route => :almanac, post: attributes_for(:post, :blog_id => @blog.id)
48
+ }.to change(Almanac::Post, :count).by(1)
49
+ end
50
+
51
+ it "redirects to the site root" do
52
+ post :create, :use_route => :almanac, post: attributes_for(:post, :blog_id => @blog.id)
53
+ response.should redirect_to root_url
54
+ end
55
+ end
56
+ context "with invalid attributes" do
57
+ it "doesn't create a new post" do
58
+ expect{
59
+ post :create, :use_route => :almanac, post: attributes_for(:post, :title => nil, :blog_id => @blog.id)
60
+ }.to_not change(Almanac::Post, :count)
61
+ end
62
+
63
+ it "re-renders the new method" do
64
+ post :create, :use_route => :almanac, post: attributes_for(:post, :title => nil, :blog_id => @blog.id)
65
+ response.should render_template :new
66
+ end
67
+ end
68
+ end
69
+
70
+ describe "PUT update" do
71
+ before :each do
72
+ @post = create(:post, :blog_id => @blog.id)
73
+ end
74
+
75
+ context "with valid attributes" do
76
+ it "changes blog's attributes" do
77
+ put :update, id: @post.id, :use_route => :almanac,
78
+ post: attributes_for(:post, title: "Testz")
79
+ @post.reload
80
+ @post.title.should eq("Testz")
81
+ end
82
+
83
+ it "redirects to the site root" do
84
+ put :update, :use_route => :almanac, id: @post.id, post: attributes_for(:post)
85
+ response.should redirect_to root_url
86
+ end
87
+ end
88
+ context "with invalid attributes" do
89
+ it "doesn't change post's attributes" do
90
+ old_title = @post.title
91
+ put :update, id: @post.id, :use_route => :almanac,
92
+ post: attributes_for(:post, title: nil)
93
+ @post.reload
94
+ @post.title.should eq(old_title)
95
+ end
96
+ it "re-renders the edit method" do
97
+ put :update, id: @post.id, :use_route => :almanac,
98
+ post: attributes_for(:post, title: nil)
99
+ response.should render_template :edit
100
+ end
101
+ end
102
+ end
103
+
104
+ describe "DELETE destroy" do
105
+ before :each do
106
+ @post = create(:post, :blog_id => @blog.id)
107
+ end
108
+
109
+ it "deletes the post" do
110
+ expect{
111
+ delete :destroy, :use_route => :almanac, id: @post.id
112
+ }.to change(Almanac::Post, :count).by(-1)
113
+ end
114
+
115
+ it "redirects to the site root" do
116
+ delete :destroy, :use_route => :almanac, id: @post
117
+ response.should redirect_to root_url
118
+ end
119
+ end
120
+ end
@@ -0,0 +1,261 @@
1
+ == Welcome to Rails
2
+
3
+ Rails is a web-application framework that includes everything needed to create
4
+ database-backed web applications according to the Model-View-Control pattern.
5
+
6
+ This pattern splits the view (also called the presentation) into "dumb"
7
+ templates that are primarily responsible for inserting pre-built data in between
8
+ HTML tags. The model contains the "smart" domain objects (such as Account,
9
+ Product, Person, Post) that holds all the business logic and knows how to
10
+ persist themselves to a database. The controller handles the incoming requests
11
+ (such as Save New Account, Update Product, Show Post) by manipulating the model
12
+ and directing data to the view.
13
+
14
+ In Rails, the model is handled by what's called an object-relational mapping
15
+ layer entitled Active Record. This layer allows you to present the data from
16
+ database rows as objects and embellish these data objects with business logic
17
+ methods. You can read more about Active Record in
18
+ link:files/vendor/rails/activerecord/README.html.
19
+
20
+ The controller and view are handled by the Action Pack, which handles both
21
+ layers by its two parts: Action View and Action Controller. These two layers
22
+ are bundled in a single package due to their heavy interdependence. This is
23
+ unlike the relationship between the Active Record and Action Pack that is much
24
+ more separate. Each of these packages can be used independently outside of
25
+ Rails. You can read more about Action Pack in
26
+ link:files/vendor/rails/actionpack/README.html.
27
+
28
+
29
+ == Getting Started
30
+
31
+ 1. At the command prompt, create a new Rails application:
32
+ <tt>rails new myapp</tt> (where <tt>myapp</tt> is the application name)
33
+
34
+ 2. Change directory to <tt>myapp</tt> and start the web server:
35
+ <tt>cd myapp; rails server</tt> (run with --help for options)
36
+
37
+ 3. Go to http://localhost:3000/ and you'll see:
38
+ "Welcome aboard: You're riding Ruby on Rails!"
39
+
40
+ 4. Follow the guidelines to start developing your application. You can find
41
+ the following resources handy:
42
+
43
+ * The Getting Started Guide: http://guides.rubyonrails.org/getting_started.html
44
+ * Ruby on Rails Tutorial Book: http://www.railstutorial.org/
45
+
46
+
47
+ == Debugging Rails
48
+
49
+ Sometimes your application goes wrong. Fortunately there are a lot of tools that
50
+ will help you debug it and get it back on the rails.
51
+
52
+ First area to check is the application log files. Have "tail -f" commands
53
+ running on the server.log and development.log. Rails will automatically display
54
+ debugging and runtime information to these files. Debugging info will also be
55
+ shown in the browser on requests from 127.0.0.1.
56
+
57
+ You can also log your own messages directly into the log file from your code
58
+ using the Ruby logger class from inside your controllers. Example:
59
+
60
+ class WeblogController < ActionController::Base
61
+ def destroy
62
+ @weblog = Weblog.find(params[:id])
63
+ @weblog.destroy
64
+ logger.info("#{Time.now} Destroyed Weblog ID ##{@weblog.id}!")
65
+ end
66
+ end
67
+
68
+ The result will be a message in your log file along the lines of:
69
+
70
+ Mon Oct 08 14:22:29 +1000 2007 Destroyed Weblog ID #1!
71
+
72
+ More information on how to use the logger is at http://www.ruby-doc.org/core/
73
+
74
+ Also, Ruby documentation can be found at http://www.ruby-lang.org/. There are
75
+ several books available online as well:
76
+
77
+ * Programming Ruby: http://www.ruby-doc.org/docs/ProgrammingRuby/ (Pickaxe)
78
+ * Learn to Program: http://pine.fm/LearnToProgram/ (a beginners guide)
79
+
80
+ These two books will bring you up to speed on the Ruby language and also on
81
+ programming in general.
82
+
83
+
84
+ == Debugger
85
+
86
+ Debugger support is available through the debugger command when you start your
87
+ Mongrel or WEBrick server with --debugger. This means that you can break out of
88
+ execution at any point in the code, investigate and change the model, and then,
89
+ resume execution! You need to install ruby-debug to run the server in debugging
90
+ mode. With gems, use <tt>sudo gem install ruby-debug</tt>. Example:
91
+
92
+ class WeblogController < ActionController::Base
93
+ def index
94
+ @posts = Post.all
95
+ debugger
96
+ end
97
+ end
98
+
99
+ So the controller will accept the action, run the first line, then present you
100
+ with a IRB prompt in the server window. Here you can do things like:
101
+
102
+ >> @posts.inspect
103
+ => "[#<Post:0x14a6be8
104
+ @attributes={"title"=>nil, "body"=>nil, "id"=>"1"}>,
105
+ #<Post:0x14a6620
106
+ @attributes={"title"=>"Rails", "body"=>"Only ten..", "id"=>"2"}>]"
107
+ >> @posts.first.title = "hello from a debugger"
108
+ => "hello from a debugger"
109
+
110
+ ...and even better, you can examine how your runtime objects actually work:
111
+
112
+ >> f = @posts.first
113
+ => #<Post:0x13630c4 @attributes={"title"=>nil, "body"=>nil, "id"=>"1"}>
114
+ >> f.
115
+ Display all 152 possibilities? (y or n)
116
+
117
+ Finally, when you're ready to resume execution, you can enter "cont".
118
+
119
+
120
+ == Console
121
+
122
+ The console is a Ruby shell, which allows you to interact with your
123
+ application's domain model. Here you'll have all parts of the application
124
+ configured, just like it is when the application is running. You can inspect
125
+ domain models, change values, and save to the database. Starting the script
126
+ without arguments will launch it in the development environment.
127
+
128
+ To start the console, run <tt>rails console</tt> from the application
129
+ directory.
130
+
131
+ Options:
132
+
133
+ * Passing the <tt>-s, --sandbox</tt> argument will rollback any modifications
134
+ made to the database.
135
+ * Passing an environment name as an argument will load the corresponding
136
+ environment. Example: <tt>rails console production</tt>.
137
+
138
+ To reload your controllers and models after launching the console run
139
+ <tt>reload!</tt>
140
+
141
+ More information about irb can be found at:
142
+ link:http://www.rubycentral.org/pickaxe/irb.html
143
+
144
+
145
+ == dbconsole
146
+
147
+ You can go to the command line of your database directly through <tt>rails
148
+ dbconsole</tt>. You would be connected to the database with the credentials
149
+ defined in database.yml. Starting the script without arguments will connect you
150
+ to the development database. Passing an argument will connect you to a different
151
+ database, like <tt>rails dbconsole production</tt>. Currently works for MySQL,
152
+ PostgreSQL and SQLite 3.
153
+
154
+ == Description of Contents
155
+
156
+ The default directory structure of a generated Ruby on Rails application:
157
+
158
+ |-- app
159
+ | |-- assets
160
+ | |-- images
161
+ | |-- javascripts
162
+ | `-- stylesheets
163
+ | |-- controllers
164
+ | |-- helpers
165
+ | |-- mailers
166
+ | |-- models
167
+ | `-- views
168
+ | `-- layouts
169
+ |-- config
170
+ | |-- environments
171
+ | |-- initializers
172
+ | `-- locales
173
+ |-- db
174
+ |-- doc
175
+ |-- lib
176
+ | `-- tasks
177
+ |-- log
178
+ |-- public
179
+ |-- script
180
+ |-- test
181
+ | |-- fixtures
182
+ | |-- functional
183
+ | |-- integration
184
+ | |-- performance
185
+ | `-- unit
186
+ |-- tmp
187
+ | |-- cache
188
+ | |-- pids
189
+ | |-- sessions
190
+ | `-- sockets
191
+ `-- vendor
192
+ |-- assets
193
+ `-- stylesheets
194
+ `-- plugins
195
+
196
+ app
197
+ Holds all the code that's specific to this particular application.
198
+
199
+ app/assets
200
+ Contains subdirectories for images, stylesheets, and JavaScript files.
201
+
202
+ app/controllers
203
+ Holds controllers that should be named like weblogs_controller.rb for
204
+ automated URL mapping. All controllers should descend from
205
+ ApplicationController which itself descends from ActionController::Base.
206
+
207
+ app/models
208
+ Holds models that should be named like post.rb. Models descend from
209
+ ActiveRecord::Base by default.
210
+
211
+ app/views
212
+ Holds the template files for the view that should be named like
213
+ weblogs/index.html.erb for the WeblogsController#index action. All views use
214
+ eRuby syntax by default.
215
+
216
+ app/views/layouts
217
+ Holds the template files for layouts to be used with views. This models the
218
+ common header/footer method of wrapping views. In your views, define a layout
219
+ using the <tt>layout :default</tt> and create a file named default.html.erb.
220
+ Inside default.html.erb, call <% yield %> to render the view using this
221
+ layout.
222
+
223
+ app/helpers
224
+ Holds view helpers that should be named like weblogs_helper.rb. These are
225
+ generated for you automatically when using generators for controllers.
226
+ Helpers can be used to wrap functionality for your views into methods.
227
+
228
+ config
229
+ Configuration files for the Rails environment, the routing map, the database,
230
+ and other dependencies.
231
+
232
+ db
233
+ Contains the database schema in schema.rb. db/migrate contains all the
234
+ sequence of Migrations for your schema.
235
+
236
+ doc
237
+ This directory is where your application documentation will be stored when
238
+ generated using <tt>rake doc:app</tt>
239
+
240
+ lib
241
+ Application specific libraries. Basically, any kind of custom code that
242
+ doesn't belong under controllers, models, or helpers. This directory is in
243
+ the load path.
244
+
245
+ public
246
+ The directory available for the web server. Also contains the dispatchers and the
247
+ default HTML files. This should be set as the DOCUMENT_ROOT of your web
248
+ server.
249
+
250
+ script
251
+ Helper scripts for automation and generation.
252
+
253
+ test
254
+ Unit and functional tests along with fixtures. When using the rails generate
255
+ command, template test files will be generated for you and placed in this
256
+ directory.
257
+
258
+ vendor
259
+ External libraries that the application depends on. Also includes the plugins
260
+ subdirectory. If the app has frozen rails, those gems also go here, under
261
+ vendor/rails/. This directory is in the load path.