From 9e6d43f9c9d7973aee9e1219aac00df3d3f49205 Mon Sep 17 00:00:00 2001 From: Ryan Bigg Date: Mon, 10 Oct 2011 08:42:27 +1100 Subject: [engines guide] finish covering what the scaffold generator does within an engine --- railties/guides/source/engines.textile | 44 ++++++++++++++++++++++++++++++++-- 1 file 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: + + +module Blorgh + class PostsController < ApplicationController + ... + end +end + + +NOTE: The +ApplicationController+ class being inherited from here is the +Blorgh::ApplicationController+, not an application's +ApplicationController+. + +The helper is also namespaced: + + +module Blorgh + class PostsHelper + ... + end +end + + +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 ++ tag of this layout: + + +<%= stylesheet_link_tag "scaffold" %> + + +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. -- cgit v1.2.3