sitemap_generator 0.1.1 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -42,38 +42,37 @@ Other "difficult" Sitemap issues, solved by this plugin:
42
42
  Installation
43
43
  =======
44
44
 
45
+ *As a gem*
46
+
47
+ 1. Add the gem as a dependency in your config/environment.rb
48
+ <code>config.gem 'sitemap_generator', :source => 'http://gemcutter.org'</code>
49
+
50
+ 2. rake gems:install
51
+
52
+ 3. Add the following line to your RAILS_ROOT/Rakefile
53
+ <code>begin require 'sitemap_generator/tasks' rescue LoadError end</code>
54
+
55
+ 4. `rake sitemap:install`
56
+
45
57
  *As a plugin*
46
58
 
47
59
  1. Install plugin as normal
48
60
 
49
61
  <code>./script/plugin install git://github.com/adamsalter/sitemap_generator-plugin.git</code>
50
62
 
51
- 2. Installation should create a 'config/sitemap.rb' file which will contain your logic for generation of the Sitemap files. (If you want to recreate this file manually run `rake sitemap:install`)
52
63
 
53
- 3. Run `rake sitemap:refresh` as needed to create Sitemap files. This will also ping all the ['major'][sitemap_engines] search engines. (if you want to disable all non-essential output run the rake task thusly `rake -s sitemap:refresh SILENT=true`)
64
+ Installation should create a 'config/sitemap.rb' file which will contain your logic for generation of the Sitemap files. (If you want to recreate this file manually run `rake sitemap:install`)
65
+
66
+ You can run `rake sitemap:refresh` as needed to create Sitemap files. This will also ping all the ['major'][sitemap_engines] search engines. (if you want to disable all non-essential output run the rake task thusly `rake -s sitemap:refresh`)
54
67
 
55
68
  Sitemaps with many urls (100,000+) take quite a long time to generate, so if you need to refresh your Sitemaps regularly you can set the rake task up as a cron job. Most cron agents will only send you an email if there is output from the cron task.
56
69
 
57
- 4. Finally, and optionally, add the following to your robots.txt file.
70
+ Optionally, you can add the following to your robots.txt file, so that robots can find the sitemap file.
58
71
 
59
72
  <code>Sitemap: &lt;hostname>/sitemap_index.xml.gz</code>
60
73
 
61
74
  The robots.txt Sitemap URL should be the complete URL to the Sitemap Index, such as: `http://www.example.org/sitemap_index.xml.gz`
62
75
 
63
- *As a gem*
64
-
65
- 1. Add the gem as a dependency in your config/environment.rb
66
- <code>config.gem 'sitemap_generator', :source => 'http://gemcutter.org'</code>
67
-
68
- 2. sudo rake gems:install
69
-
70
- 3. Add the following line to your Rails.root/Rakefile
71
- <code>begin require 'sitemap_generator/tasks' rescue LoadError end</code>
72
-
73
- 4. <code>rake sitemap:install</code>
74
-
75
- 5. Follow steps 2-4 above
76
-
77
76
 
78
77
  Example 'config/sitemap.rb'
79
78
  ==========
@@ -123,6 +122,15 @@ Notes
123
122
  end
124
123
  end
125
124
 
125
+ 3) New Capistrano deploys will remove your Sitemap files, unless you run `rake sitemap:refresh`. The way around this is to create a cap task:
126
+
127
+ after "deploy:update_code", "deploy:copy_old_sitemap"
128
+
129
+ namespace :deploy do
130
+ task :copy_old_sitemap do
131
+ run "if [ -e #{previous_release}/public/sitemap_index.xml.gz ]; then cp #{previous_release}/public/sitemap* #{current_release}/public/; fi"
132
+ end
133
+ end
126
134
 
127
135
  Known Bugs
128
136
  ========
data/Rakefile CHANGED
@@ -3,24 +3,24 @@ require 'find'
3
3
 
4
4
  begin
5
5
  require 'jeweler'
6
- Jeweler::Tasks.new do |gem|
7
- gem.name = "sitemap_generator"
8
- gem.summary = %Q{This plugin enables 'enterprise-class' Google Sitemaps to be easily generated for a Rails site as a rake task}
9
- gem.description = %Q{This plugin enables 'enterprise-class' Google Sitemaps to be easily generated for a Rails site as a rake task}
10
- gem.email = "adam@salter.net "
11
- gem.homepage = "http://github.com/adamsalter/sitemap_generator-plugin"
12
- gem.authors = ["Adam Salter"]
13
- # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
6
+ Jeweler::Tasks.new do |s|
7
+ s.name = "sitemap_generator"
8
+ s.summary = %Q{This plugin enables 'enterprise-class' Google Sitemaps to be easily generated for a Rails site as a rake task}
9
+ s.description = %Q{This plugin enables 'enterprise-class' Google Sitemaps to be easily generated for a Rails site as a rake task}
10
+ s.email = "adam.salter@codebright.net "
11
+ s.homepage = "http://github.com/adamsalter/sitemap_generator-plugin"
12
+ s.authors = ["Adam Salter"]
13
+ s.files = FileList["[A-Z]*", "{bin,lib,rails,templates}/**/*"]
14
+ # s is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
14
15
  end
15
-
16
16
  rescue LoadError
17
- puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
17
+ puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
18
18
  end
19
19
 
20
20
  desc 'Default: run unit tests.'
21
21
  task :default => :test
22
22
 
23
- desc 'Test ActiveScaffold.'
23
+ desc 'Test.'
24
24
  Rake::TestTask.new(:test) do |t|
25
25
  t.libs << 'lib'
26
26
  t.pattern = 'test/**/*_test.rb'
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.1
1
+ 0.2.0
@@ -40,9 +40,9 @@ module SitemapGenerator
40
40
  begin
41
41
  unless SitemapGenerator::Sitemap.yahoo_app_id == false
42
42
  open(link)
43
- puts "Successful ping of #{engine.to_s.titleize}" unless ENV['SILENT'].present?
43
+ puts "Successful ping of #{engine.to_s.titleize}" if verbose
44
44
  end
45
- rescue StandardError => e
45
+ rescue Timeout::Error, StandardError => e
46
46
  puts "Ping failed for #{engine.to_s.titleize}: #{e.inspect}"
47
47
  puts <<-END if engine == :yahoo
48
48
  Yahoo requires an 'AppID' for more than one ping per "timeframe", you can either:
@@ -1 +1 @@
1
- load "#{File.dirname(__FILE__)}/../../tasks/sitemap_generator_tasks.rake"
1
+ load "#{File.dirname(__FILE__)}/../../tasks/sitemap_generator_tasks.rake"
File without changes
File without changes
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sitemap_generator
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Adam Salter
@@ -9,12 +9,12 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-11-02 00:00:00 -05:00
12
+ date: 2009-11-06 00:00:00 +11:00
13
13
  default_executable:
14
14
  dependencies: []
15
15
 
16
16
  description: This plugin enables 'enterprise-class' Google Sitemaps to be easily generated for a Rails site as a rake task
17
- email: "adam@salter.net "
17
+ email: "adam.salter@codebright.net "
18
18
  executables: []
19
19
 
20
20
  extensions: []
@@ -22,53 +22,21 @@ extensions: []
22
22
  extra_rdoc_files:
23
23
  - README.md
24
24
  files:
25
- - .autotest
26
- - .gitignore
27
25
  - MIT-LICENSE
28
26
  - README.md
29
27
  - Rakefile
30
28
  - VERSION
31
- - init.rb
32
- - install.rb
33
29
  - lib/sitemap_generator.rb
34
30
  - lib/sitemap_generator/helper.rb
35
31
  - lib/sitemap_generator/link.rb
36
32
  - lib/sitemap_generator/link_set.rb
37
33
  - lib/sitemap_generator/mapper.rb
38
34
  - lib/sitemap_generator/tasks.rb
39
- - sitemap_generator.gemspec
40
- - tasks/sitemap_generator_tasks.rake
35
+ - rails/install.rb
36
+ - rails/uninstall.rb
41
37
  - templates/sitemap.rb
42
38
  - templates/sitemap_index.builder
43
39
  - templates/xml_sitemap.builder
44
- - test/mock_app/.gitignore
45
- - test/mock_app/README
46
- - test/mock_app/Rakefile
47
- - test/mock_app/app/controllers/application_controller.rb
48
- - test/mock_app/app/controllers/contents_controller.rb
49
- - test/mock_app/app/models/content.rb
50
- - test/mock_app/config/boot.rb
51
- - test/mock_app/config/database.yml
52
- - test/mock_app/config/environment.rb
53
- - test/mock_app/config/environments/development.rb
54
- - test/mock_app/config/environments/production.rb
55
- - test/mock_app/config/environments/test.rb
56
- - test/mock_app/config/initializers/backtrace_silencers.rb
57
- - test/mock_app/config/initializers/inflections.rb
58
- - test/mock_app/config/initializers/mime_types.rb
59
- - test/mock_app/config/initializers/new_rails_defaults.rb
60
- - test/mock_app/config/initializers/session_store.rb
61
- - test/mock_app/config/locales/en.yml
62
- - test/mock_app/config/routes.rb
63
- - test/mock_app/config/sitemap.rb
64
- - test/mock_app/db/migrate/20090826121911_create_contents.rb
65
- - test/mock_app/db/schema.rb
66
- - test/mock_app/db/test.sqlite3
67
- - test/mock_app/public/index.html
68
- - test/mock_app/script/console
69
- - test/sitemap_generator_test.rb
70
- - test/test_helper.rb
71
- - uninstall.rb
72
40
  has_rdoc: true
73
41
  homepage: http://github.com/adamsalter/sitemap_generator-plugin
74
42
  licenses: []
data/.autotest DELETED
@@ -1,36 +0,0 @@
1
- class Autotest
2
- ##
3
- # Convert a path in a string, s, into a class name, changing
4
- # underscores to CamelCase, etc.
5
-
6
- def path_to_classname(s)
7
- sep = File::SEPARATOR
8
- f = s.sub(/^test#{sep}/, '').sub(/\.rb$/, '').split(sep)
9
- f = f.map { |path| path.split(/_|(\d+)/).map { |seg| seg.capitalize }.join }
10
- f = f.map { |path| path =~ /Test$/ ? path : "#{path}Test" }
11
- f.join('::')
12
- end
13
- end
14
-
15
- Autotest.add_hook :initialize do |at|
16
- unless ARGV.empty?
17
- if ARGV[0] == '-d'
18
- at.find_directories = ARGV[1..-1].dup
19
- else
20
- at.find_directories = []
21
- at.extra_files = ARGV.dup
22
- end
23
- end
24
-
25
- # doesn't seem to work
26
- # at.clear_mappings
27
-
28
- at.add_mapping(/^lib\/.*\.rb$/) do |filename, _|
29
- possible = File.basename(filename, 'rb').gsub '_', '_?'
30
- files_matching %r%^test/.*#{possible}_test\.rb$%
31
- end
32
-
33
- at.add_mapping(/^test.*\/.*test\.rb$/) do |filename, _|
34
- filename
35
- end
36
- end
data/.gitignore DELETED
@@ -1,2 +0,0 @@
1
- pkg
2
- *.swp
data/init.rb DELETED
@@ -1,2 +0,0 @@
1
- # Include hook code here
2
-
@@ -1,103 +0,0 @@
1
- # Generated by jeweler
2
- # DO NOT EDIT THIS FILE
3
- # Instead, edit Jeweler::Tasks in Rakefile, and run `rake gemspec`
4
- # -*- encoding: utf-8 -*-
5
-
6
- Gem::Specification.new do |s|
7
- s.name = %q{sitemap_generator}
8
- s.version = "0.1.1"
9
-
10
- s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
- s.authors = ["Adam Salter"]
12
- s.date = %q{2009-11-02}
13
- s.description = %q{This plugin enables 'enterprise-class' Google Sitemaps to be easily generated for a Rails site as a rake task}
14
- s.email = %q{adam@salter.net }
15
- s.extra_rdoc_files = [
16
- "README.md"
17
- ]
18
- s.files = [
19
- ".autotest",
20
- ".gitignore",
21
- "MIT-LICENSE",
22
- "README.md",
23
- "Rakefile",
24
- "VERSION",
25
- "init.rb",
26
- "install.rb",
27
- "lib/sitemap_generator.rb",
28
- "lib/sitemap_generator/helper.rb",
29
- "lib/sitemap_generator/link.rb",
30
- "lib/sitemap_generator/link_set.rb",
31
- "lib/sitemap_generator/mapper.rb",
32
- "lib/sitemap_generator/tasks.rb",
33
- "sitemap_generator.gemspec",
34
- "tasks/sitemap_generator_tasks.rake",
35
- "templates/sitemap.rb",
36
- "templates/sitemap_index.builder",
37
- "templates/xml_sitemap.builder",
38
- "test/mock_app/.gitignore",
39
- "test/mock_app/README",
40
- "test/mock_app/Rakefile",
41
- "test/mock_app/app/controllers/application_controller.rb",
42
- "test/mock_app/app/controllers/contents_controller.rb",
43
- "test/mock_app/app/models/content.rb",
44
- "test/mock_app/config/boot.rb",
45
- "test/mock_app/config/database.yml",
46
- "test/mock_app/config/environment.rb",
47
- "test/mock_app/config/environments/development.rb",
48
- "test/mock_app/config/environments/production.rb",
49
- "test/mock_app/config/environments/test.rb",
50
- "test/mock_app/config/initializers/backtrace_silencers.rb",
51
- "test/mock_app/config/initializers/inflections.rb",
52
- "test/mock_app/config/initializers/mime_types.rb",
53
- "test/mock_app/config/initializers/new_rails_defaults.rb",
54
- "test/mock_app/config/initializers/session_store.rb",
55
- "test/mock_app/config/locales/en.yml",
56
- "test/mock_app/config/routes.rb",
57
- "test/mock_app/config/sitemap.rb",
58
- "test/mock_app/db/migrate/20090826121911_create_contents.rb",
59
- "test/mock_app/db/schema.rb",
60
- "test/mock_app/db/test.sqlite3",
61
- "test/mock_app/public/index.html",
62
- "test/mock_app/script/console",
63
- "test/sitemap_generator_test.rb",
64
- "test/test_helper.rb",
65
- "uninstall.rb"
66
- ]
67
- s.homepage = %q{http://github.com/adamsalter/sitemap_generator-plugin}
68
- s.rdoc_options = ["--charset=UTF-8"]
69
- s.require_paths = ["lib"]
70
- s.rubygems_version = %q{1.3.5}
71
- s.summary = %q{This plugin enables 'enterprise-class' Google Sitemaps to be easily generated for a Rails site as a rake task}
72
- s.test_files = [
73
- "test/mock_app/app/controllers/application_controller.rb",
74
- "test/mock_app/app/controllers/contents_controller.rb",
75
- "test/mock_app/app/models/content.rb",
76
- "test/mock_app/config/boot.rb",
77
- "test/mock_app/config/environment.rb",
78
- "test/mock_app/config/environments/development.rb",
79
- "test/mock_app/config/environments/production.rb",
80
- "test/mock_app/config/environments/test.rb",
81
- "test/mock_app/config/initializers/backtrace_silencers.rb",
82
- "test/mock_app/config/initializers/inflections.rb",
83
- "test/mock_app/config/initializers/mime_types.rb",
84
- "test/mock_app/config/initializers/new_rails_defaults.rb",
85
- "test/mock_app/config/initializers/session_store.rb",
86
- "test/mock_app/config/routes.rb",
87
- "test/mock_app/config/sitemap.rb",
88
- "test/mock_app/db/migrate/20090826121911_create_contents.rb",
89
- "test/mock_app/db/schema.rb",
90
- "test/sitemap_generator_test.rb",
91
- "test/test_helper.rb"
92
- ]
93
-
94
- if s.respond_to? :specification_version then
95
- current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
96
- s.specification_version = 3
97
-
98
- if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
99
- else
100
- end
101
- else
102
- end
103
- end
@@ -1,74 +0,0 @@
1
- require 'zlib'
2
-
3
- namespace :sitemap do
4
-
5
- desc "Install a default config/sitemap.rb file"
6
- task :install do
7
- load File.expand_path(File.join(File.dirname(__FILE__), "..", "install.rb"))
8
- end
9
-
10
- desc "Delete all Sitemap files in public/ directory"
11
- task :clean do
12
- sitemap_files = Dir[File.join(RAILS_ROOT, 'public/sitemap*.xml.gz')]
13
- FileUtils.rm sitemap_files
14
- end
15
-
16
- desc "Create Sitemap XML files in public/ directory"
17
- desc "Create Sitemap XML files in public/ directory (set SILENT=true for no output)"
18
- task :refresh => ['sitemap:create'] do
19
- ping_search_engines("sitemap_index.xml.gz")
20
- end
21
-
22
- desc "Create Sitemap XML files (don't ping search engines)"
23
- task 'refresh:no_ping' => ['sitemap:create'] do
24
- end
25
-
26
- task :create => [:environment] do
27
- include SitemapGenerator::Helper
28
- include ActionView::Helpers::NumberHelper
29
-
30
- start_time = Time.now
31
-
32
- # update links from config/sitemap.rb
33
- load_sitemap_rb
34
-
35
- raise(ArgumentError, "Default hostname not defined") if SitemapGenerator::Sitemap.default_host.blank?
36
-
37
- links_grps = SitemapGenerator::Sitemap.links.in_groups_of(50000, false)
38
- raise(ArgumentError, "TOO MANY LINKS!! I really thought 2,500,000,000 links would be enough for anybody!") if links_grps.length > 50000
39
-
40
- Rake::Task['sitemap:clean'].invoke
41
-
42
- # render individual sitemaps
43
- sitemap_files = []
44
- xml_sitemap_template = File.join(File.dirname(__FILE__), '../templates/xml_sitemap.builder')
45
- links_grps.each_with_index do |links, index|
46
- buffer = ''
47
- xml = Builder::XmlMarkup.new(:target=>buffer)
48
- eval(open(xml_sitemap_template).read, binding)
49
- filename = File.join(RAILS_ROOT, "public/sitemap#{index+1}.xml.gz")
50
- Zlib::GzipWriter.open(filename) do |gz|
51
- gz.write buffer
52
- end
53
- puts "+ #{filename}" unless ENV['SILENT'].present?
54
- puts "** Sitemap too big! The uncompressed size exceeds 10Mb" if (buffer.size > 10 * 1024 * 1024) && ENV['SILENT'].blank?
55
- sitemap_files << filename
56
- end
57
-
58
- # render index
59
- sitemap_index_template = File.join(File.dirname(__FILE__), '../templates/sitemap_index.builder')
60
- buffer = ''
61
- xml = Builder::XmlMarkup.new(:target=>buffer)
62
- eval(open(sitemap_index_template).read, binding)
63
- filename = File.join(RAILS_ROOT, "public/sitemap_index.xml.gz")
64
- Zlib::GzipWriter.open(filename) do |gz|
65
- gz.write buffer
66
- end
67
- puts "+ #{filename}" unless ENV['SILENT'].present?
68
- puts "** Sitemap Index too big! The uncompressed size exceeds 10Mb" if (buffer.size > 10 * 1024 * 1024) && ENV['SILENT'].blank?
69
-
70
- stop_time = Time.now
71
- puts "Sitemap stats: #{number_with_delimiter(SitemapGenerator::Sitemap.links.length)} links, " + ("%dm%02ds" % (stop_time - start_time).divmod(60)) unless ENV['SILENT'].present?
72
-
73
- end
74
- end
@@ -1,3 +0,0 @@
1
- tmp
2
- log
3
- public/sitemap*
data/test/mock_app/README DELETED
@@ -1,243 +0,0 @@
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" templates
7
- that are primarily responsible for inserting pre-built data in between HTML tags.
8
- The model contains the "smart" domain objects (such as Account, Product, Person,
9
- Post) that holds all the business logic and knows how to persist themselves to
10
- a database. The controller handles the incoming requests (such as Save New Account,
11
- Update 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 <tt>rails</tt> command
31
- and your application name. Ex: rails myapp
32
- 2. Change directory into myapp and start the web server: <tt>script/server</tt> (run with --help for options)
33
- 3. Go to http://localhost:3000/ and get "Welcome aboard: You're riding the Rails!"
34
- 4. Follow the guidelines to start developing your application
35
-
36
-
37
- == Web Servers
38
-
39
- By default, Rails will try to use Mongrel if it's are installed when started with script/server, otherwise Rails will use WEBrick, the webserver that ships with Ruby. But you can also use Rails
40
- with a variety of other web servers.
41
-
42
- Mongrel is a Ruby-based webserver with a C component (which requires compilation) that is
43
- suitable for development and deployment of Rails applications. If you have Ruby Gems installed,
44
- getting up and running with mongrel is as easy as: <tt>gem install mongrel</tt>.
45
- More info at: http://mongrel.rubyforge.org
46
-
47
- Say other Ruby web servers like Thin and Ebb or regular web servers like Apache or LiteSpeed or
48
- Lighttpd or IIS. The Ruby web servers are run through Rack and the latter can either be setup to use
49
- FCGI or proxy to a pack of Mongrels/Thin/Ebb servers.
50
-
51
- == Apache .htaccess example for FCGI/CGI
52
-
53
- # General Apache options
54
- AddHandler fastcgi-script .fcgi
55
- AddHandler cgi-script .cgi
56
- Options +FollowSymLinks +ExecCGI
57
-
58
- # If you don't want Rails to look in certain directories,
59
- # use the following rewrite rules so that Apache won't rewrite certain requests
60
- #
61
- # Example:
62
- # RewriteCond %{REQUEST_URI} ^/notrails.*
63
- # RewriteRule .* - [L]
64
-
65
- # Redirect all requests not available on the filesystem to Rails
66
- # By default the cgi dispatcher is used which is very slow
67
- #
68
- # For better performance replace the dispatcher with the fastcgi one
69
- #
70
- # Example:
71
- # RewriteRule ^(.*)$ dispatch.fcgi [QSA,L]
72
- RewriteEngine On
73
-
74
- # If your Rails application is accessed via an Alias directive,
75
- # then you MUST also set the RewriteBase in this htaccess file.
76
- #
77
- # Example:
78
- # Alias /myrailsapp /path/to/myrailsapp/public
79
- # RewriteBase /myrailsapp
80
-
81
- RewriteRule ^$ index.html [QSA]
82
- RewriteRule ^([^.]+)$ $1.html [QSA]
83
- RewriteCond %{REQUEST_FILENAME} !-f
84
- RewriteRule ^(.*)$ dispatch.cgi [QSA,L]
85
-
86
- # In case Rails experiences terminal errors
87
- # Instead of displaying this message you can supply a file here which will be rendered instead
88
- #
89
- # Example:
90
- # ErrorDocument 500 /500.html
91
-
92
- ErrorDocument 500 "<h2>Application error</h2>Rails application failed to start properly"
93
-
94
-
95
- == Debugging Rails
96
-
97
- Sometimes your application goes wrong. Fortunately there are a lot of tools that
98
- will help you debug it and get it back on the rails.
99
-
100
- First area to check is the application log files. Have "tail -f" commands running
101
- on the server.log and development.log. Rails will automatically display debugging
102
- and runtime information to these files. Debugging info will also be shown in the
103
- browser on requests from 127.0.0.1.
104
-
105
- You can also log your own messages directly into the log file from your code using
106
- the Ruby logger class from inside your controllers. Example:
107
-
108
- class WeblogController < ActionController::Base
109
- def destroy
110
- @weblog = Weblog.find(params[:id])
111
- @weblog.destroy
112
- logger.info("#{Time.now} Destroyed Weblog ID ##{@weblog.id}!")
113
- end
114
- end
115
-
116
- The result will be a message in your log file along the lines of:
117
-
118
- Mon Oct 08 14:22:29 +1000 2007 Destroyed Weblog ID #1
119
-
120
- More information on how to use the logger is at http://www.ruby-doc.org/core/
121
-
122
- Also, Ruby documentation can be found at http://www.ruby-lang.org/ including:
123
-
124
- * The Learning Ruby (Pickaxe) Book: http://www.ruby-doc.org/docs/ProgrammingRuby/
125
- * Learn to Program: http://pine.fm/LearnToProgram/ (a beginners guide)
126
-
127
- These two online (and free) books will bring you up to speed on the Ruby language
128
- and also on programming in general.
129
-
130
-
131
- == Debugger
132
-
133
- Debugger support is available through the debugger command when you start your Mongrel or
134
- Webrick server with --debugger. This means that you can break out of execution at any point
135
- in the code, investigate and change the model, AND then resume execution!
136
- You need to install ruby-debug to run the server in debugging mode. With gems, use 'gem install ruby-debug'
137
- Example:
138
-
139
- class WeblogController < ActionController::Base
140
- def index
141
- @posts = Post.find(:all)
142
- debugger
143
- end
144
- end
145
-
146
- So the controller will accept the action, run the first line, then present you
147
- with a IRB prompt in the server window. Here you can do things like:
148
-
149
- >> @posts.inspect
150
- => "[#<Post:0x14a6be8 @attributes={\"title\"=>nil, \"body\"=>nil, \"id\"=>\"1\"}>,
151
- #<Post:0x14a6620 @attributes={\"title\"=>\"Rails you know!\", \"body\"=>\"Only ten..\", \"id\"=>\"2\"}>]"
152
- >> @posts.first.title = "hello from a debugger"
153
- => "hello from a debugger"
154
-
155
- ...and even better is that you can examine how your runtime objects actually work:
156
-
157
- >> f = @posts.first
158
- => #<Post:0x13630c4 @attributes={"title"=>nil, "body"=>nil, "id"=>"1"}>
159
- >> f.
160
- Display all 152 possibilities? (y or n)
161
-
162
- Finally, when you're ready to resume execution, you enter "cont"
163
-
164
-
165
- == Console
166
-
167
- You can interact with the domain model by starting the console through <tt>script/console</tt>.
168
- Here you'll have all parts of the application configured, just like it is when the
169
- application is running. You can inspect domain models, change values, and save to the
170
- database. Starting the script without arguments will launch it in the development environment.
171
- Passing an argument will specify a different environment, like <tt>script/console production</tt>.
172
-
173
- To reload your controllers and models after launching the console run <tt>reload!</tt>
174
-
175
- == dbconsole
176
-
177
- You can go to the command line of your database directly through <tt>script/dbconsole</tt>.
178
- You would be connected to the database with the credentials defined in database.yml.
179
- Starting the script without arguments will connect you to the development database. Passing an
180
- argument will connect you to a different database, like <tt>script/dbconsole production</tt>.
181
- Currently works for mysql, postgresql and sqlite.
182
-
183
- == Description of Contents
184
-
185
- app
186
- Holds all the code that's specific to this particular application.
187
-
188
- app/controllers
189
- Holds controllers that should be named like weblogs_controller.rb for
190
- automated URL mapping. All controllers should descend from ApplicationController
191
- which itself descends from ActionController::Base.
192
-
193
- app/models
194
- Holds models that should be named like post.rb.
195
- Most models will descend from ActiveRecord::Base.
196
-
197
- app/views
198
- Holds the template files for the view that should be named like
199
- weblogs/index.html.erb for the WeblogsController#index action. All views use eRuby
200
- syntax.
201
-
202
- app/views/layouts
203
- Holds the template files for layouts to be used with views. This models the common
204
- header/footer method of wrapping views. In your views, define a layout using the
205
- <tt>layout :default</tt> and create a file named default.html.erb. Inside default.html.erb,
206
- call <% yield %> to render the view using this layout.
207
-
208
- app/helpers
209
- Holds view helpers that should be named like weblogs_helper.rb. These are generated
210
- for you automatically when using script/generate for controllers. Helpers can be used to
211
- wrap functionality for your views into methods.
212
-
213
- config
214
- Configuration files for the Rails environment, the routing map, the database, and other dependencies.
215
-
216
- db
217
- Contains the database schema in schema.rb. db/migrate contains all
218
- the sequence of Migrations for your schema.
219
-
220
- doc
221
- This directory is where your application documentation will be stored when generated
222
- using <tt>rake doc:app</tt>
223
-
224
- lib
225
- Application specific libraries. Basically, any kind of custom code that doesn't
226
- belong under controllers, models, or helpers. This directory is in the load path.
227
-
228
- public
229
- The directory available for the web server. Contains subdirectories for images, stylesheets,
230
- and javascripts. Also contains the dispatchers and the default HTML files. This should be
231
- set as the DOCUMENT_ROOT of your web server.
232
-
233
- script
234
- Helper scripts for automation and generation.
235
-
236
- test
237
- Unit and functional tests along with fixtures. When using the script/generate scripts, template
238
- test files will be generated for you and placed in this directory.
239
-
240
- vendor
241
- External libraries that the application depends on. Also includes the plugins subdirectory.
242
- If the app has frozen rails, those gems also go here, under vendor/rails/.
243
- This directory is in the load path.
@@ -1,10 +0,0 @@
1
- # Add your own tasks in files placed in lib/tasks ending in .rake,
2
- # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
3
-
4
- require(File.join(File.dirname(__FILE__), 'config', 'boot'))
5
-
6
- require 'rake'
7
- require 'rake/testtask'
8
- require 'rake/rdoctask'
9
-
10
- require 'tasks/rails'
@@ -1,5 +0,0 @@
1
- test:
2
- adapter: sqlite3
3
- database: db/test.sqlite3
4
- pool: 5
5
- timeout: 5000
@@ -1,5 +0,0 @@
1
- # Sample localization file for English. Add more files in this directory for other locales.
2
- # See http://github.com/svenfuchs/rails-i18n/tree/master/rails%2Flocale for starting points.
3
-
4
- en:
5
- hello: "Hello world"
Binary file
@@ -1,275 +0,0 @@
1
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
2
- "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
3
- <html>
4
- <head>
5
- <meta http-equiv="Content-type" content="text/html; charset=utf-8" />
6
- <title>Ruby on Rails: Welcome aboard</title>
7
- <style type="text/css" media="screen">
8
- body {
9
- margin: 0;
10
- margin-bottom: 25px;
11
- padding: 0;
12
- background-color: #f0f0f0;
13
- font-family: "Lucida Grande", "Bitstream Vera Sans", "Verdana";
14
- font-size: 13px;
15
- color: #333;
16
- }
17
-
18
- h1 {
19
- font-size: 28px;
20
- color: #000;
21
- }
22
-
23
- a {color: #03c}
24
- a:hover {
25
- background-color: #03c;
26
- color: white;
27
- text-decoration: none;
28
- }
29
-
30
-
31
- #page {
32
- background-color: #f0f0f0;
33
- width: 750px;
34
- margin: 0;
35
- margin-left: auto;
36
- margin-right: auto;
37
- }
38
-
39
- #content {
40
- float: left;
41
- background-color: white;
42
- border: 3px solid #aaa;
43
- border-top: none;
44
- padding: 25px;
45
- width: 500px;
46
- }
47
-
48
- #sidebar {
49
- float: right;
50
- width: 175px;
51
- }
52
-
53
- #footer {
54
- clear: both;
55
- }
56
-
57
-
58
- #header, #about, #getting-started {
59
- padding-left: 75px;
60
- padding-right: 30px;
61
- }
62
-
63
-
64
- #header {
65
- background-image: url("images/rails.png");
66
- background-repeat: no-repeat;
67
- background-position: top left;
68
- height: 64px;
69
- }
70
- #header h1, #header h2 {margin: 0}
71
- #header h2 {
72
- color: #888;
73
- font-weight: normal;
74
- font-size: 16px;
75
- }
76
-
77
-
78
- #about h3 {
79
- margin: 0;
80
- margin-bottom: 10px;
81
- font-size: 14px;
82
- }
83
-
84
- #about-content {
85
- background-color: #ffd;
86
- border: 1px solid #fc0;
87
- margin-left: -11px;
88
- }
89
- #about-content table {
90
- margin-top: 10px;
91
- margin-bottom: 10px;
92
- font-size: 11px;
93
- border-collapse: collapse;
94
- }
95
- #about-content td {
96
- padding: 10px;
97
- padding-top: 3px;
98
- padding-bottom: 3px;
99
- }
100
- #about-content td.name {color: #555}
101
- #about-content td.value {color: #000}
102
-
103
- #about-content.failure {
104
- background-color: #fcc;
105
- border: 1px solid #f00;
106
- }
107
- #about-content.failure p {
108
- margin: 0;
109
- padding: 10px;
110
- }
111
-
112
-
113
- #getting-started {
114
- border-top: 1px solid #ccc;
115
- margin-top: 25px;
116
- padding-top: 15px;
117
- }
118
- #getting-started h1 {
119
- margin: 0;
120
- font-size: 20px;
121
- }
122
- #getting-started h2 {
123
- margin: 0;
124
- font-size: 14px;
125
- font-weight: normal;
126
- color: #333;
127
- margin-bottom: 25px;
128
- }
129
- #getting-started ol {
130
- margin-left: 0;
131
- padding-left: 0;
132
- }
133
- #getting-started li {
134
- font-size: 18px;
135
- color: #888;
136
- margin-bottom: 25px;
137
- }
138
- #getting-started li h2 {
139
- margin: 0;
140
- font-weight: normal;
141
- font-size: 18px;
142
- color: #333;
143
- }
144
- #getting-started li p {
145
- color: #555;
146
- font-size: 13px;
147
- }
148
-
149
-
150
- #search {
151
- margin: 0;
152
- padding-top: 10px;
153
- padding-bottom: 10px;
154
- font-size: 11px;
155
- }
156
- #search input {
157
- font-size: 11px;
158
- margin: 2px;
159
- }
160
- #search-text {width: 170px}
161
-
162
-
163
- #sidebar ul {
164
- margin-left: 0;
165
- padding-left: 0;
166
- }
167
- #sidebar ul h3 {
168
- margin-top: 25px;
169
- font-size: 16px;
170
- padding-bottom: 10px;
171
- border-bottom: 1px solid #ccc;
172
- }
173
- #sidebar li {
174
- list-style-type: none;
175
- }
176
- #sidebar ul.links li {
177
- margin-bottom: 5px;
178
- }
179
-
180
- </style>
181
- <script type="text/javascript" src="javascripts/prototype.js"></script>
182
- <script type="text/javascript" src="javascripts/effects.js"></script>
183
- <script type="text/javascript">
184
- function about() {
185
- if (Element.empty('about-content')) {
186
- new Ajax.Updater('about-content', 'rails/info/properties', {
187
- method: 'get',
188
- onFailure: function() {Element.classNames('about-content').add('failure')},
189
- onComplete: function() {new Effect.BlindDown('about-content', {duration: 0.25})}
190
- });
191
- } else {
192
- new Effect[Element.visible('about-content') ?
193
- 'BlindUp' : 'BlindDown']('about-content', {duration: 0.25});
194
- }
195
- }
196
-
197
- window.onload = function() {
198
- $('search-text').value = '';
199
- $('search').onsubmit = function() {
200
- $('search-text').value = 'site:rubyonrails.org ' + $F('search-text');
201
- }
202
- }
203
- </script>
204
- </head>
205
- <body>
206
- <div id="page">
207
- <div id="sidebar">
208
- <ul id="sidebar-items">
209
- <li>
210
- <form id="search" action="http://www.google.com/search" method="get">
211
- <input type="hidden" name="hl" value="en" />
212
- <input type="text" id="search-text" name="q" value="site:rubyonrails.org " />
213
- <input type="submit" value="Search" /> the Rails site
214
- </form>
215
- </li>
216
-
217
- <li>
218
- <h3>Join the community</h3>
219
- <ul class="links">
220
- <li><a href="http://www.rubyonrails.org/">Ruby on Rails</a></li>
221
- <li><a href="http://weblog.rubyonrails.org/">Official weblog</a></li>
222
- <li><a href="http://wiki.rubyonrails.org/">Wiki</a></li>
223
- </ul>
224
- </li>
225
-
226
- <li>
227
- <h3>Browse the documentation</h3>
228
- <ul class="links">
229
- <li><a href="http://api.rubyonrails.org/">Rails API</a></li>
230
- <li><a href="http://stdlib.rubyonrails.org/">Ruby standard library</a></li>
231
- <li><a href="http://corelib.rubyonrails.org/">Ruby core</a></li>
232
- <li><a href="http://guides.rubyonrails.org/">Rails Guides</a></li>
233
- </ul>
234
- </li>
235
- </ul>
236
- </div>
237
-
238
- <div id="content">
239
- <div id="header">
240
- <h1>Welcome aboard</h1>
241
- <h2>You&rsquo;re riding Ruby on Rails!</h2>
242
- </div>
243
-
244
- <div id="about">
245
- <h3><a href="rails/info/properties" onclick="about(); return false">About your application&rsquo;s environment</a></h3>
246
- <div id="about-content" style="display: none"></div>
247
- </div>
248
-
249
- <div id="getting-started">
250
- <h1>Getting started</h1>
251
- <h2>Here&rsquo;s how to get rolling:</h2>
252
-
253
- <ol>
254
- <li>
255
- <h2>Use <tt>script/generate</tt> to create your models and controllers</h2>
256
- <p>To see all available options, run it without parameters.</p>
257
- </li>
258
-
259
- <li>
260
- <h2>Set up a default route and remove or rename this file</h2>
261
- <p>Routes are set up in config/routes.rb.</p>
262
- </li>
263
-
264
- <li>
265
- <h2>Create your database</h2>
266
- <p>Run <tt>rake db:migrate</tt> to create your database. If you're not using SQLite (the default), edit <tt>config/database.yml</tt> with your username and password.</p>
267
- </li>
268
- </ol>
269
- </div>
270
- </div>
271
-
272
- <div id="footer">&nbsp;</div>
273
- </div>
274
- </body>
275
- </html>
@@ -1,3 +0,0 @@
1
- #!/usr/bin/env ruby
2
- require File.dirname(__FILE__) + '/../config/boot'
3
- require 'commands/console'