If you like go a bit more in depth,
      please read Piotr Sarnacki article:

http://piotrsarnacki.com/2010/06/18/rails-i...
Poke into Rails 3 railites


           Priit Tamboom
        priit@gitnation.com

             London
            13.09.2...
puts 'Hello!'



                  Early days...
              Not so early days...
                 Recent days...
...or ...
Presentation is about:

 Railtie and it's responsibilty
Engine and Application classes
          Initialization

   ...and...
Credits and thanks goes to:


            Rails 3 source code
            Rails 3 edge guides
 José Valim and other Devise...
What's the responsibility of Railites:



              Glues all together
     Handles all bootstrapping process
    Prov...
What about class Railtie?
                railties/lib/rails/railtie.rb




  Class Railtie is the core of the Rails Frame...
Creating your own Railtie
# APP/Gemfile
gem 'my_gem'

# GEM/lib/my_gem.rb
requrie 'my_gem/railtie' if defined?(Rails)

# G...
What about Engine class?




First, don't get confused with Engine plugin.
Rails 3 Engine class is quite different thing.
Engine is just subclass of Railtie



# railties/lib/rails/engine.rb
module Rails
 class Engine < Railtie
 end
end
Available paths in an Engine

class MyEngine < Rails::Engine
 paths.app                 = "app"
 paths.app.controllers    ...
Use middleware in initialization


# lib/my_gem/railtie.rb
class MyRailtie < Rails::Railtie
 initializer "my_railtie.initi...
One more thing :-)
What to expect from Rails 3.1?
What, not excited?
Anyhow, heavy lifting done by Piotr Sarnacki in
his time with Ruby Summer of Code.

At the moment treat his work as any ot...
What to expect from Rails 3.1?


* Engine is now rack application
* Added middleware stack to Engine
* Engine can now load...
What to expect from Rails 3.1?

* Task for copying plugins' and engines'
migrations to application's db/migrate directory
...
Good news




It looks Rails 3.1 will probably be very friendly for
             multible/mountable apps.
Bad news


 Please, don't go crazy with mountable apps,
             even with Rails 3.1

In my reality it's a pipe dream ...
However there is nish



Take a look how Devise works and what kind
     workflow/attitude José Valim has.
He has given a ...
Thank you for you time!


Any questions or comments?


     Just in case, here is my profiles:
              Github.com/pr...
Upcoming SlideShare
Loading in …5
×

Railties

2,337 views
2,293 views

Published on


Recently I have been porting an app into Rails 3 and probably you have

also been poking this new Rails 3 with ruby 1.9.2.

Therefore I would like to discuss a bit more about Rails 3 itself.

Particularly, things under railties lib directory covering classes

such as Railtie, Engine, Application and will go through

initialization with initializers.

Along the way I'll show some examples how you can use this knowledge

in your own gem or plugin.


Nothing too fancy but should be useful for developing your next Rails




Published in: Technology
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
2,337
On SlideShare
0
From Embeds
0
Number of Embeds
91
Actions
Shares
0
Downloads
16
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide

Railties

  1. 1. If you like go a bit more in depth, please read Piotr Sarnacki article: http://piotrsarnacki.com/2010/06/18/rails-internals-railties/ Anyhow, here is my slides for meetup.
  2. 2. Poke into Rails 3 railites Priit Tamboom priit@gitnation.com London 13.09.2010
  3. 3. puts 'Hello!' Early days... Not so early days... Recent days... ...or just short shameless self presentation.
  4. 4. Presentation is about: Railtie and it's responsibilty Engine and Application classes Initialization ...and one more thing ;-)
  5. 5. Credits and thanks goes to: Rails 3 source code Rails 3 edge guides José Valim and other Devise developers Piotr Sarnacki and his summer work/blog http://piotrsarnacki.com Own experience during summer in Barcelona
  6. 6. What's the responsibility of Railites: Glues all together Handles all bootstrapping process Provides rails command line interface Provides rails generators core
  7. 7. What about class Railtie? railties/lib/rails/railtie.rb Class Railtie is the core of the Rails Framework and provides several hooks to extend Rails and/or modify the initialization process.
  8. 8. Creating your own Railtie # APP/Gemfile gem 'my_gem' # GEM/lib/my_gem.rb requrie 'my_gem/railtie' if defined?(Rails) # GEM/lib/my_gem/railtie.rb module MyGem class Railtie < Rails::Railtie end end
  9. 9. What about Engine class? First, don't get confused with Engine plugin. Rails 3 Engine class is quite different thing.
  10. 10. Engine is just subclass of Railtie # railties/lib/rails/engine.rb module Rails class Engine < Railtie end end
  11. 11. Available paths in an Engine class MyEngine < Rails::Engine paths.app = "app" paths.app.controllers = "app/controllers" paths.app.helpers = "app/helpers" paths.app.models = "app/models" paths.app.views = "app/views" paths.lib = "lib" paths.lib.tasks = "lib/tasks" paths.config = "config" paths.config.initializers = "config/initializers" paths.config.locales = "config/locales" paths.config.routes = "config/routes.rb" end
  12. 12. Use middleware in initialization # lib/my_gem/railtie.rb class MyRailtie < Rails::Railtie initializer "my_railtie.initialization" do |app| app.middleware.use MyRailtie::Middleware end end
  13. 13. One more thing :-)
  14. 14. What to expect from Rails 3.1?
  15. 15. What, not excited?
  16. 16. Anyhow, heavy lifting done by Piotr Sarnacki in his time with Ruby Summer of Code. At the moment treat his work as any other Rails edge code, I'm sure he welcomes any feedback.
  17. 17. What to expect from Rails 3.1? * Engine is now rack application * Added middleware stack to Engine * Engine can now load plugins * Engine can load its own environment file * Added helpers to call engines' route helpers from application and vice versa
  18. 18. What to expect from Rails 3.1? * Task for copying plugins' and engines' migrations to application's db/migrate directory * Changed ActionDispatch::Static to allow handling multiple directories * Added namespace() method to Engine, which sets Engine as isolated * Include all helpers from plugins and shared engines in application
  19. 19. Good news It looks Rails 3.1 will probably be very friendly for multible/mountable apps.
  20. 20. Bad news Please, don't go crazy with mountable apps, even with Rails 3.1 In my reality it's a pipe dream to create and use very high level dependencies.
  21. 21. However there is nish Take a look how Devise works and what kind workflow/attitude José Valim has. He has given a nice introduction about this topic in Barcelona, probably there will be something on online as well.
  22. 22. Thank you for you time! Any questions or comments? Just in case, here is my profiles: Github.com/priit Twitter.com/priit http://priit.mx.ee priit@gitnation.com

×