Rails::Engine                      @flaviamissi                flaviamissi.com.br
What is a engine?                <<                             slicesengine
What is a engine?●    Works exactly as a built-in rails application●    Railtie    ●        Active Record    ●        Acti...
Application -> Engine -> Railtie   module Rails         class Application < Engine         ...         class Engine < Rail...
http://www.flickr.com/photos/imelda/1022089050/sizes/l/in/photostream/
Creating Our Engine App     $ rails new MyApp
What you dont need $ rm -rf log/ $ rm -rf tmp/ $ rm -rf doc/ $ rm -rf vendor/ $ rm -rf config/enviroments/ $ rm -rf config...
And We Have Now...
A Simple Blog App$ rails g scaffold Blog::Post title:string post:text            namespace!
routes.rbEngine::Application.routes.draw do Rails.application.routes.draw do
config/application.rbmodule MyApp  class Application < Rails::Applicationmodule MyApp  class Engine < Rails::Engine
Integrating With Another App$ cp -R ~/my_engine ~/my_app/vendor/plugins/
Integrating With Another App                                    $ rake routesblog_posts     GET /blog/posts(.:format)     ...
Só isso?!http://www.flickr.com/photos/bee721/5784266118/
A Problem...Migrations and everything inside public/are not available to the main application
The Solutionnamespace :engine do  task :create, :engine do |cmd, args|     puts "Creating symbolic links..."     system "m...
Some Interesting Links●  https://github.com/search?q=rack&type=Everything&repo=&langOverride=&start_●  http://akitaonrails...
Upcoming SlideShare
Loading in …5
×

Rails::Engine

4,267 views
4,192 views

Published on

Introduction to Rails Engines

0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
4,267
On SlideShare
0
From Embeds
0
Number of Embeds
2,606
Actions
Shares
0
Downloads
11
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Rails::Engine

  1. 1. Rails::Engine @flaviamissi flaviamissi.com.br
  2. 2. What is a engine? << slicesengine
  3. 3. What is a engine?● Works exactly as a built-in rails application● Railtie ● Active Record ● Active Resource ● Action Mailer ● Action Controller ● Action View
  4. 4. Application -> Engine -> Railtie module Rails class Application < Engine ... class Engine < Railtie ... ... https://github.com/rails/rails/blob/master/railties/lib/rails/application.rb https://github.com/rails/rails/blob/master/railties/lib/rails/engine.rb
  5. 5. http://www.flickr.com/photos/imelda/1022089050/sizes/l/in/photostream/
  6. 6. Creating Our Engine App $ rails new MyApp
  7. 7. What you dont need $ rm -rf log/ $ rm -rf tmp/ $ rm -rf doc/ $ rm -rf vendor/ $ rm -rf config/enviroments/ $ rm -rf config/initializers/ * $ rm -rf config/boot.rb * $ rm -rf script/ * * = later!
  8. 8. And We Have Now...
  9. 9. A Simple Blog App$ rails g scaffold Blog::Post title:string post:text namespace!
  10. 10. routes.rbEngine::Application.routes.draw do Rails.application.routes.draw do
  11. 11. config/application.rbmodule MyApp class Application < Rails::Applicationmodule MyApp class Engine < Rails::Engine
  12. 12. Integrating With Another App$ cp -R ~/my_engine ~/my_app/vendor/plugins/
  13. 13. Integrating With Another App $ rake routesblog_posts GET /blog/posts(.:format) {:action=>"index", :controller=>"blog/posts"} POST /blog/posts(.:format) {:action=>"create", :controller=>"blog/posts"}new_blog_post GET /blog/posts/new(.:format) {:action=>"new", :controller=>"blog/posts"}edit_blog_post GET /blog/posts/:id/edit(.:format) {:action=>"edit", :controller=>"blog/posts"}blog_post GET /blog/posts/:id(.:format) {:action=>"show", :controller=>"blog/posts"} PUT /blog/posts/:id(.:format) {:action=>"update", :controller=>"blog/posts"} DELETE /blog/posts/:id(.:format) {:action=>"destroy", :controller=>"blog/posts"}
  14. 14. Só isso?!http://www.flickr.com/photos/bee721/5784266118/
  15. 15. A Problem...Migrations and everything inside public/are not available to the main application
  16. 16. The Solutionnamespace :engine do task :create, :engine do |cmd, args| puts "Creating symbolic links..." system "mkdir #{Rails.root.to_s}/public/#{args[:engin system "ln -s #{Rails.root.to_s}/vendor/plugins/#{arg system "ln -s #{Rails.root.to_s}/vendor/plugins/#{arg puts "Done!" endend
  17. 17. Some Interesting Links● https://github.com/search?q=rack&type=Everything&repo=&langOverride=&start_● http://akitaonrails.com/2010/05/10/rails-3-introducao-a-engines● http://api.rubyonrails.org/classes/Rails/Engine.html● http://api.rubyonrails.org/classes/Rails/Railtie.html

×