comfortable_mexican_sofa 0.0.18
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +10 -0
- data/CHANGELOG.rdoc +2 -0
- data/LICENSE +20 -0
- data/README.rdoc +55 -0
- data/Rakefile +88 -0
- data/VERSION +1 -0
- data/app/controllers/cms_admin/attachments_controller.rb +55 -0
- data/app/controllers/cms_admin/base_controller.rb +25 -0
- data/app/controllers/cms_admin/categories_controller.rb +69 -0
- data/app/controllers/cms_admin/layouts_controller.rb +71 -0
- data/app/controllers/cms_admin/pages_controller.rb +79 -0
- data/app/controllers/cms_admin/sections_controller.rb +17 -0
- data/app/controllers/cms_admin/snippets_controller.rb +58 -0
- data/app/controllers/cms_common/render_page.rb +47 -0
- data/app/controllers/cms_content_controller.rb +30 -0
- data/app/helpers/cms_helper.rb +12 -0
- data/app/models/cms_attachment.rb +17 -0
- data/app/models/cms_attachment_categorization.rb +5 -0
- data/app/models/cms_block.rb +15 -0
- data/app/models/cms_category.rb +36 -0
- data/app/models/cms_layout.rb +102 -0
- data/app/models/cms_page.rb +125 -0
- data/app/models/cms_page_categorization.rb +6 -0
- data/app/models/cms_snippet.rb +15 -0
- data/app/views/cms_admin/attachments/_details.html.haml +27 -0
- data/app/views/cms_admin/attachments/_form.html.haml +24 -0
- data/app/views/cms_admin/attachments/edit.html.haml +10 -0
- data/app/views/cms_admin/attachments/index.html.haml +36 -0
- data/app/views/cms_admin/attachments/new.html.haml +8 -0
- data/app/views/cms_admin/categories/_category.html.haml +21 -0
- data/app/views/cms_admin/categories/_category_subform.html.haml +12 -0
- data/app/views/cms_admin/categories/_form.html.haml +18 -0
- data/app/views/cms_admin/categories/_new.html.haml +7 -0
- data/app/views/cms_admin/categories/_toggle_link.html.haml +9 -0
- data/app/views/cms_admin/categories/_tree_branch.html.haml +36 -0
- data/app/views/cms_admin/categories/children.js.rjs +10 -0
- data/app/views/cms_admin/categories/create.js.rjs +9 -0
- data/app/views/cms_admin/categories/edit.html.haml +10 -0
- data/app/views/cms_admin/categories/index.html.haml +7 -0
- data/app/views/cms_admin/categories/new.html.haml +8 -0
- data/app/views/cms_admin/categories/show.html.haml +17 -0
- data/app/views/cms_admin/layouts/_details.html.haml +6 -0
- data/app/views/cms_admin/layouts/_form.html.haml +19 -0
- data/app/views/cms_admin/layouts/_toggle_link.html.haml +9 -0
- data/app/views/cms_admin/layouts/_tree_branch.html.haml +39 -0
- data/app/views/cms_admin/layouts/children.js.rjs +10 -0
- data/app/views/cms_admin/layouts/edit.html.haml +10 -0
- data/app/views/cms_admin/layouts/index.html.haml +7 -0
- data/app/views/cms_admin/layouts/new.html.haml +8 -0
- data/app/views/cms_admin/pages/_details.html.haml +25 -0
- data/app/views/cms_admin/pages/_form.html.haml +45 -0
- data/app/views/cms_admin/pages/_form_blocks.html.haml +48 -0
- data/app/views/cms_admin/pages/_toggle_link.html.haml +10 -0
- data/app/views/cms_admin/pages/_tree_branch.html.haml +41 -0
- data/app/views/cms_admin/pages/children.js.rjs +10 -0
- data/app/views/cms_admin/pages/edit.html.haml +11 -0
- data/app/views/cms_admin/pages/form_blocks.js.rjs +1 -0
- data/app/views/cms_admin/pages/index.html.haml +6 -0
- data/app/views/cms_admin/pages/new.html.haml +9 -0
- data/app/views/cms_admin/sections/show.html.haml +23 -0
- data/app/views/cms_admin/snippets/_form.html.haml +10 -0
- data/app/views/cms_admin/snippets/edit.html.haml +10 -0
- data/app/views/cms_admin/snippets/index.html.haml +26 -0
- data/app/views/cms_admin/snippets/new.html.haml +8 -0
- data/app/views/cms_content/show.xml.rxml +27 -0
- data/app/views/cms_content/sitemap.xml.rxml +16 -0
- data/app/views/layouts/cms_admin.html.haml +44 -0
- data/comfortable_mexican_sofa.gemspec +254 -0
- data/config/cms_routes.rb +25 -0
- data/generators/cms/cms_generator.rb +55 -0
- data/generators/cms/templates/README +32 -0
- data/generators/cms/templates/images/arrow_bottom.gif +0 -0
- data/generators/cms/templates/images/arrow_right.gif +0 -0
- data/generators/cms/templates/images/icon_attachment.gif +0 -0
- data/generators/cms/templates/images/icon_category.gif +0 -0
- data/generators/cms/templates/images/icon_draft.gif +0 -0
- data/generators/cms/templates/images/icon_layout.gif +0 -0
- data/generators/cms/templates/images/icon_move.gif +0 -0
- data/generators/cms/templates/images/icon_regular.gif +0 -0
- data/generators/cms/templates/images/icon_snippet.gif +0 -0
- data/generators/cms/templates/images/logo.png +0 -0
- data/generators/cms/templates/initializers/cms.rb +14 -0
- data/generators/cms/templates/initializers/paperclip.rb +14 -0
- data/generators/cms/templates/javascripts/codemirror_init.js +16 -0
- data/generators/cms/templates/javascripts/mce_init.js +17 -0
- data/generators/cms/templates/javascripts/utilities.js +27 -0
- data/generators/cms/templates/migrations/create_cms.rb +113 -0
- data/generators/cms/templates/stylesheets/cms_master.sass +414 -0
- data/init.rb +1 -0
- data/lib/comfortable_mexican_sofa.rb +46 -0
- data/lib/comfortable_mexican_sofa/acts_as_categorized.rb +87 -0
- data/lib/comfortable_mexican_sofa/acts_as_published.rb +60 -0
- data/lib/comfortable_mexican_sofa/cms_acts_as_tree.rb +108 -0
- data/lib/comfortable_mexican_sofa/cms_rails_extensions.rb +12 -0
- data/lib/comfortable_mexican_sofa/cms_tag.rb +109 -0
- data/lib/comfortable_mexican_sofa/cms_tags/attachment.rb +3 -0
- data/lib/comfortable_mexican_sofa/cms_tags/block.rb +117 -0
- data/lib/comfortable_mexican_sofa/cms_tags/helper.rb +3 -0
- data/lib/comfortable_mexican_sofa/cms_tags/page_block.rb +119 -0
- data/lib/comfortable_mexican_sofa/cms_tags/partial.rb +19 -0
- data/lib/comfortable_mexican_sofa/cms_tags/snippet.rb +19 -0
- data/rails/init.rb +1 -0
- data/test/fixtures/cms_attachment_categorizations.yml +7 -0
- data/test/fixtures/cms_attachments.yml +6 -0
- data/test/fixtures/cms_blocks.yml +38 -0
- data/test/fixtures/cms_categories.yml +19 -0
- data/test/fixtures/cms_layouts.yml +41 -0
- data/test/fixtures/cms_page_categorizations.yml +15 -0
- data/test/fixtures/cms_pages.yml +38 -0
- data/test/fixtures/cms_snippets.yml +7 -0
- data/test/fixtures/files/upload_file.txt +1 -0
- data/test/functional/cms_admin/attachments_controller_test.rb +63 -0
- data/test/functional/cms_admin/categories_controller_test.rb +86 -0
- data/test/functional/cms_admin/layouts_controller_test.rb +77 -0
- data/test/functional/cms_admin/pages_controller_test.rb +153 -0
- data/test/functional/cms_admin/sections_controller_test.rb +9 -0
- data/test/functional/cms_admin/snippets_controller_test.rb +63 -0
- data/test/functional/cms_content_controller_test.rb +52 -0
- data/test/models/cms_attachment_test.rb +16 -0
- data/test/models/cms_block_test.rb +11 -0
- data/test/models/cms_categorization_test.rb +39 -0
- data/test/models/cms_category_test.rb +71 -0
- data/test/models/cms_layout_test.rb +44 -0
- data/test/models/cms_page_test.rb +55 -0
- data/test/models/cms_snippet_test.rb +16 -0
- data/test/models/cms_tag_test.rb +70 -0
- data/test/rails_root/README +243 -0
- data/test/rails_root/Rakefile +10 -0
- data/test/rails_root/app/controllers/application_controller.rb +10 -0
- data/test/rails_root/app/helpers/application_helper.rb +3 -0
- data/test/rails_root/app/views/cms/under-development.html.haml +1 -0
- data/test/rails_root/app/views/complex_page/_example.html.erb +1 -0
- data/test/rails_root/config/boot.rb +110 -0
- data/test/rails_root/config/database.yml +22 -0
- data/test/rails_root/config/environment.rb +48 -0
- data/test/rails_root/config/environments/development.rb +17 -0
- data/test/rails_root/config/environments/production.rb +28 -0
- data/test/rails_root/config/environments/test.rb +28 -0
- data/test/rails_root/config/initializers/backtrace_silencers.rb +7 -0
- data/test/rails_root/config/initializers/inflections.rb +10 -0
- data/test/rails_root/config/initializers/mime_types.rb +5 -0
- data/test/rails_root/config/initializers/new_rails_defaults.rb +19 -0
- data/test/rails_root/config/initializers/session_store.rb +15 -0
- data/test/rails_root/config/locales/en.yml +5 -0
- data/test/rails_root/config/routes.rb +43 -0
- data/test/rails_root/doc/README_FOR_APP +2 -0
- data/test/rails_root/public/404.html +30 -0
- data/test/rails_root/public/422.html +30 -0
- data/test/rails_root/public/500.html +30 -0
- data/test/rails_root/public/favicon.ico +0 -0
- data/test/rails_root/public/images/rails.png +0 -0
- data/test/rails_root/public/index.html +275 -0
- data/test/rails_root/public/javascripts/application.js +2 -0
- data/test/rails_root/public/javascripts/controls.js +963 -0
- data/test/rails_root/public/javascripts/dragdrop.js +973 -0
- data/test/rails_root/public/javascripts/effects.js +1128 -0
- data/test/rails_root/public/javascripts/prototype.js +4320 -0
- data/test/rails_root/public/robots.txt +5 -0
- data/test/rails_root/public/stylesheets/sass/cms_master.sass +414 -0
- data/test/rails_root/script/about +4 -0
- data/test/rails_root/script/console +3 -0
- data/test/rails_root/script/dbconsole +3 -0
- data/test/rails_root/script/destroy +3 -0
- data/test/rails_root/script/generate +3 -0
- data/test/rails_root/script/performance/benchmarker +3 -0
- data/test/rails_root/script/performance/profiler +3 -0
- data/test/rails_root/script/plugin +3 -0
- data/test/rails_root/script/runner +3 -0
- data/test/rails_root/script/server +3 -0
- data/test/test_helper.rb +17 -0
- metadata +303 -0
@@ -0,0 +1,44 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class CmsLayoutTest < ActiveSupport::TestCase
|
4
|
+
|
5
|
+
def test_fixtures_validity
|
6
|
+
CmsLayout.all.each do |layout|
|
7
|
+
assert layout.valid?, layout.errors.full_messages
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
def test_nested_layouts
|
12
|
+
parent_layout = cms_layouts(:default)
|
13
|
+
child_layout = cms_layouts(:nested)
|
14
|
+
assert_equal parent_layout, child_layout.parent
|
15
|
+
assert parent_layout.is_extendable?
|
16
|
+
|
17
|
+
assert_not_equal child_layout.content, child_layout.read_attribute(:content)
|
18
|
+
parent_layout_content = '{{ cms_block:header:string }}{{ cms_page_block:default:text }}{{ cms_page_block:footer:text }}'
|
19
|
+
child_layout_content = '{{ cms_block:header:string }}{{ cms_page_block:left_column:text }}{{ cms_page_block:right_column:text }}{{ cms_snippet:complex_snippet }}{{ cms_page_block:footer:text }}'
|
20
|
+
|
21
|
+
assert_equal parent_layout_content, parent_layout.content
|
22
|
+
assert_equal child_layout_content, child_layout.content
|
23
|
+
end
|
24
|
+
|
25
|
+
def test_adding_new_block_tag_updates_associated_pages
|
26
|
+
layout = cms_layouts(:default)
|
27
|
+
page = cms_pages(:default)
|
28
|
+
assert_equal layout, page.cms_layout
|
29
|
+
assert_equal 3, layout.tags.size
|
30
|
+
assert_equal 3, layout.tags.select{|t| ['cms_block', 'cms_page_block'].member?(t.tag_type)}.size
|
31
|
+
assert_equal 3, page.cms_blocks.count
|
32
|
+
|
33
|
+
assert_difference ['layout.tags.size', 'page.cms_blocks.count'] do
|
34
|
+
layout.content += "{{cms_block:new_block:string}}"
|
35
|
+
layout.save!
|
36
|
+
layout.reload
|
37
|
+
page.reload
|
38
|
+
|
39
|
+
assert layout.tags.collect{|t| t.tag_signature}.member?('cms_block:new_block:string')
|
40
|
+
assert page.cms_blocks.with_label('new_block')
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class CmsPageTest < ActiveSupport::TestCase
|
4
|
+
|
5
|
+
def test_fixtures_validity
|
6
|
+
CmsPage.all.each do |page|
|
7
|
+
assert page.valid?, page.errors.full_messages
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
def test_page_finder_helper
|
12
|
+
page = cms_pages(:default)
|
13
|
+
assert_equal page, CmsPage[page.slug]
|
14
|
+
end
|
15
|
+
|
16
|
+
def test_page_rendering
|
17
|
+
page = cms_pages(:default)
|
18
|
+
assert_equal 3, page.cms_blocks.count
|
19
|
+
assert_equal '/page_block:default//page_block:footer/', page.render_content
|
20
|
+
end
|
21
|
+
|
22
|
+
def test_complex_nested_rendering
|
23
|
+
page = cms_pages(:complex)
|
24
|
+
assert_equal 4, page.cms_blocks.count
|
25
|
+
assert_equal "/page_block:left_column/ /complex snippet//page_block:right_column/ <%= render :partial => 'complex_page/example' %>/complex snippet//page_block:footer/", page.render_content
|
26
|
+
end
|
27
|
+
|
28
|
+
def test_page_content
|
29
|
+
page = cms_pages(:default)
|
30
|
+
assert_equal page.content, page.render_content
|
31
|
+
end
|
32
|
+
|
33
|
+
def test_cms_block_content_method
|
34
|
+
page = cms_pages(:default)
|
35
|
+
assert !page.cms_block_content(:header, :content_string).blank?
|
36
|
+
assert page.cms_block_content(:bogus_label, :content_string).blank?
|
37
|
+
end
|
38
|
+
|
39
|
+
def test_publishing
|
40
|
+
page = cms_pages(:default)
|
41
|
+
assert page.published_at < Time.now.utc
|
42
|
+
assert page.unpublished_at.nil?
|
43
|
+
assert page.is_published?
|
44
|
+
|
45
|
+
page.update_attribute(:published_at, 5.days.from_now)
|
46
|
+
assert !page.is_published?
|
47
|
+
|
48
|
+
page.publish!
|
49
|
+
assert page.is_published?
|
50
|
+
|
51
|
+
page.unpublish!
|
52
|
+
assert !page.is_published?
|
53
|
+
end
|
54
|
+
|
55
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class CmsSnippetTest < ActiveSupport::TestCase
|
4
|
+
|
5
|
+
def test_fixtures_validity
|
6
|
+
CmsSnippet.all.each do |snippet|
|
7
|
+
assert snippet.valid?, snippet.errors.full_messages
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
def test_get_content
|
12
|
+
assert_equal cms_snippets(:complex).content, CmsSnippet.content_for('complex_snippet')
|
13
|
+
assert_equal '', CmsSnippet.content_for('nonexistant_snippet')
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
@@ -0,0 +1,70 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class CmsTagTest < ActiveSupport::TestCase
|
4
|
+
|
5
|
+
def test_tag_parsing
|
6
|
+
layout = cms_layouts(:all_included_tags)
|
7
|
+
tags = CmsTag::parse_tags(layout.content)
|
8
|
+
assert_equal 4, tags.size
|
9
|
+
end
|
10
|
+
|
11
|
+
def test_block_tag
|
12
|
+
layout = cms_layouts(:all_included_tags)
|
13
|
+
tag = layout.tags.select{|t| t.tag_signature == 'cms_block:test_block:string'}.first
|
14
|
+
assert tag
|
15
|
+
assert_equal 'cms_block', tag.tag_type
|
16
|
+
assert_equal 'test_block', tag.label
|
17
|
+
assert_equal 'string', tag.format
|
18
|
+
|
19
|
+
assert_equal 1, tag.class.render_priority
|
20
|
+
|
21
|
+
# TODO: content pulling
|
22
|
+
end
|
23
|
+
|
24
|
+
def test_page_block_tag
|
25
|
+
layout = cms_layouts(:all_included_tags)
|
26
|
+
tag = layout.tags.select{|t| t.tag_signature == 'cms_page_block:test_page_block:string'}.first
|
27
|
+
assert tag
|
28
|
+
assert_equal 'cms_page_block', tag.tag_type
|
29
|
+
assert_equal 'test_page_block', tag.label
|
30
|
+
assert_equal 'string', tag.format
|
31
|
+
|
32
|
+
assert_equal 1, tag.class.render_priority
|
33
|
+
|
34
|
+
# TODO: content pulling
|
35
|
+
end
|
36
|
+
|
37
|
+
def test_snippet_tag
|
38
|
+
layout = cms_layouts(:all_included_tags)
|
39
|
+
tag = layout.tags.select{|t| t.tag_signature == 'cms_snippet:test_snippet'}.first
|
40
|
+
assert tag
|
41
|
+
assert_equal 'cms_snippet', tag.tag_type
|
42
|
+
assert_equal 'test_snippet', tag.label
|
43
|
+
|
44
|
+
assert_equal 2, tag.class.render_priority
|
45
|
+
|
46
|
+
# TODO: content pulling
|
47
|
+
end
|
48
|
+
|
49
|
+
def test_partial_tag
|
50
|
+
layout = cms_layouts(:all_included_tags)
|
51
|
+
tag = layout.tags.select{|t| t.tag_signature == 'cms_partial:content/test_partial'}.first
|
52
|
+
assert tag
|
53
|
+
assert_equal 'cms_partial', tag.tag_type
|
54
|
+
assert_equal 'content/test_partial', tag.label
|
55
|
+
|
56
|
+
assert_equal 3, tag.class.render_priority
|
57
|
+
assert_equal "<%= render :partial => 'content/test_partial' %>", tag.content
|
58
|
+
end
|
59
|
+
|
60
|
+
def test_tag_uniqueness
|
61
|
+
layout = cms_layouts(:identical_tags)
|
62
|
+
assert_equal 3, layout.tags.size
|
63
|
+
tag_signatures = %w(cms_block:my_block_1:text cms_block:my_block_2:integer cms_block:my_block_3:boolean)
|
64
|
+
layout.tags.each do |tag|
|
65
|
+
assert tag_signatures.member?(tag.tag_signature)
|
66
|
+
assert_equal tag.class, CmsTag::Block
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
end
|
@@ -0,0 +1,243 @@
|
|
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.
|
@@ -0,0 +1,10 @@
|
|
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'
|
@@ -0,0 +1,10 @@
|
|
1
|
+
# Filters added to this controller apply to all controllers in the application.
|
2
|
+
# Likewise, all the methods added will be available for all controllers.
|
3
|
+
|
4
|
+
class ApplicationController < ActionController::Base
|
5
|
+
helper :all # include all helpers, all the time
|
6
|
+
protect_from_forgery # See ActionController::RequestForgeryProtection for details
|
7
|
+
|
8
|
+
# Scrub sensitive parameters from your log
|
9
|
+
# filter_parameter_logging :password
|
10
|
+
end
|