diff options
Diffstat (limited to 'railties/guides/source/rails_application_templates.textile')
-rw-r--r-- | railties/guides/source/rails_application_templates.textile | 28 |
1 files changed, 17 insertions, 11 deletions
diff --git a/railties/guides/source/rails_application_templates.textile b/railties/guides/source/rails_application_templates.textile index 1bf9cfec33..8e51f9e23b 100644 --- a/railties/guides/source/rails_application_templates.textile +++ b/railties/guides/source/rails_application_templates.textile @@ -20,7 +20,7 @@ $ rails new blog -m ~/template.rb It's also possible to apply a template using a URL : <shell> -$ rails new blog -m http://gist.github.com/31208.txt +$ rails new blog -m https://gist.github.com/755496.txt </shell> Alternatively, you can use the rake task +rails:template+ to apply a template to an existing Rails application : @@ -37,7 +37,7 @@ Rails templates API is very self explanatory and easy to understand. Here's an e # template.rb run "rm public/index.html" generate(:scaffold, "person name:string") -route "map.root :controller => 'people'" +route "root :to => 'people#index'" rake("db:migrate") git :init @@ -49,7 +49,7 @@ The following sections outlines the primary methods provided by the API : h4. gem(name, options = {}) -Adds a +config.gem+ entry for the supplied gem to the generated application’s +config/environment.rb+. +Adds a +gem+ entry for the supplied gem to the generated application’s +Gemfile+. For example, if your application depends on the gems +bj+ and +nokogiri+ : @@ -66,6 +66,16 @@ rake "gems:install" And let Rails take care of installing the required gems if they’re not already installed. +h4. add_source(source, options = {}) + +Adds the given source to the generated application's +Gemfile+. + +For example, if you need to source a gem from "http://code.whytheluckystiff.net": + +<ruby> +add_source "http://code.whytheluckystiff.net" +</ruby> + h4. plugin(name, options = {}) Installs a plugin to the generated application. @@ -79,7 +89,7 @@ plugin 'authentication', :git => 'git://github.com/foor/bar.git' You can even install plugins as git submodules : <ruby> -plugin 'authentication', :git => 'git://github.com/foor/bar.git', +plugin 'authentication', :git => 'git://github.com/foor/bar.git', :submodule => true </ruby> @@ -103,7 +113,7 @@ class Object def not_nil? !nil? end - + def not_blank? !blank? end @@ -183,12 +193,12 @@ h4. route(routing_code) This adds a routing entry to the +config/routes.rb+ file. In above steps, we generated a person scaffold and also removed +public/index.html+. Now to make +PeopleController#index+ as the default page for the application : <ruby> -route "map.root :controller => :person" +route "root :to => 'person#index'" </ruby> h4. inside(dir) -I have my edge rails lying at +~/commit-rails/rails+. So every time i have to manually symlink edge from my new app. But now : +Enables you to run a command from the given directory. For example, if you have a copy of edge rails that you wish to symlink from your new apps, you can do this: <ruby> inside('vendor') do @@ -196,8 +206,6 @@ inside('vendor') do end </ruby> -So +inside()+ runs the command from the given directory. - h4. ask(question) +ask()+ gives you a chance to get some feedback from the user and use it in your templates. Lets say you want your user to name the new shiny library you’re adding : @@ -233,6 +241,4 @@ git :commit => "-a -m 'Initial commit'" h3. Changelog -"Lighthouse ticket":http://rails.lighthouseapp.com/projects/16213-rails-guides/tickets/78 - * April 29, 2009: Initial version by "Pratik":credits.html#lifo |