diff options
author | Ryan Bigg <radarlistener@gmail.com> | 2011-10-10 08:42:27 +1100 |
---|---|---|
committer | Ryan Bigg <radarlistener@gmail.com> | 2011-10-10 21:04:26 +1100 |
commit | 9e6d43f9c9d7973aee9e1219aac00df3d3f49205 (patch) | |
tree | 7000909c1151c98d08ff1c1de4abe3121fa8a2d0 /railties/guides/source/engines.textile | |
parent | da030cf9cb335c2fd3deea3cdd474fa5c69fde48 (diff) | |
download | rails-9e6d43f9c9d7973aee9e1219aac00df3d3f49205.tar.gz rails-9e6d43f9c9d7973aee9e1219aac00df3d3f49205.tar.bz2 rails-9e6d43f9c9d7973aee9e1219aac00df3d3f49205.zip |
[engines guide] finish covering what the scaffold generator does within an engine
Diffstat (limited to 'railties/guides/source/engines.textile')
-rw-r--r-- | railties/guides/source/engines.textile | 44 |
1 files changed, 42 insertions, 2 deletions
diff --git a/railties/guides/source/engines.textile b/railties/guides/source/engines.textile index 201dbd542e..b495b175e3 100644 --- a/railties/guides/source/engines.textile +++ b/railties/guides/source/engines.textile @@ -152,8 +152,48 @@ end Note here that the routes are drawn upon the +Blorgh::Engine+ object rather than the +YourApp::Application+ class. This is so that the engine routes are confined to the engine itself and can be mounted at a specific point as shown in the "test directory":#test-directory section. -TODO: Brief explanation of what this engine is going to be doing and what we will have once we are done. -TODO: Generate a posts scaffold (maybe?) for the engine +Next, the +scaffold_controller+ generator is invoked, generating a controlled called +Blorgh::PostsController+ (at +app/controllers/blorgh/posts_controller.rb+) and its related views at +app/views/blorgh/posts+. This generator also generates a functional test for the controller (+test/functional/blorgh/posts_controller_test.rb+) and a helper (+app/helpers/blorgh/posts_controller.rb+). + +Everything this generator has generated is neatly namespaced. The controller's class is defined within the +Blorgh+ module: + +<ruby> +module Blorgh + class PostsController < ApplicationController + ... + end +end +</ruby> + +NOTE: The +ApplicationController+ class being inherited from here is the +Blorgh::ApplicationController+, not an application's +ApplicationController+. + +The helper is also namespaced: + +<ruby> +module Blorgh + class PostsHelper + ... + end +end +</ruby> + +This helps prevent conflicts with any other engine or application that may have a post resource also. + +Finally, two files that are the assets for this resource are generated, +app/assets/javascripts/blorgh/posts.js+ and +app/assets/javascripts/blorgh/posts.css+. You'll see how to use these a little later. + +By default, the scaffold styling is not applied to the engine as the engine's layout file, +app/views/blorgh/application.html.erb+ doesn't load it. To make this apply, insert this line into the +<head>+ tag of this layout: + +<erb> +<%= stylesheet_link_tag "scaffold" %> +</erb> + +You can see what the engine has so far by running +rake db:migrate+ at the root of our engine to run the migration generated by the scaffold generator, and then running +rails server+. When you open +http://localhost:3000/blorgh/posts+ you will see the default scaffold that has been generated. + +!images/engines_scaffold.png(Blank engine scaffold)! + +Click around! You've just generated your first engine's first functions. + +h4. Generating a comments resource + TODO: Generate a comments scaffold (maybe?) for the engine TODO: Mention usage of `rails s` and `rails c` within the context of an engine. |