rails engine :: modularize you app
DESCRIPTION
It contains rails engine basics, and answers of some wh question regarding rails engineTRANSCRIPT
![Page 1: Rails Engine :: modularize you app](https://reader033.vdocuments.pub/reader033/viewer/2022051208/547451e3b4af9fbe0a8b577e/html5/thumbnails/1.jpg)
Rails EngineAn awesome tool to extend your rails application
Muntasim AhmedPlatform Architect @ Tasawr Interactive
https://github.com/[email protected]
![Page 2: Rails Engine :: modularize you app](https://reader033.vdocuments.pub/reader033/viewer/2022051208/547451e3b4af9fbe0a8b577e/html5/thumbnails/2.jpg)
Agenda
• Why Rails Engine• What is Rails Engine• How it works with Rails Core• Who are they• Where is your interest
![Page 3: Rails Engine :: modularize you app](https://reader033.vdocuments.pub/reader033/viewer/2022051208/547451e3b4af9fbe0a8b577e/html5/thumbnails/3.jpg)
Problems
• Large application without reusable component• Slow testing ( if any :) )• Larger app, messy
![Page 4: Rails Engine :: modularize you app](https://reader033.vdocuments.pub/reader033/viewer/2022051208/547451e3b4af9fbe0a8b577e/html5/thumbnails/4.jpg)
Solution• Find common functionalities• Extract them to module => Gems• Use railtie to tie with Rails App => Rails Engine
![Page 5: Rails Engine :: modularize you app](https://reader033.vdocuments.pub/reader033/viewer/2022051208/547451e3b4af9fbe0a8b577e/html5/thumbnails/5.jpg)
One Thing!
Rails (version>=3.1) is just a “supercharged” engine
http://edgeguides.rubyonrails.org/engines.html
![Page 6: Rails Engine :: modularize you app](https://reader033.vdocuments.pub/reader033/viewer/2022051208/547451e3b4af9fbe0a8b577e/html5/thumbnails/6.jpg)
Rails Engine ?
• pre-packaged application • able to be run or mounted within another Rails
application• can have its own models, views, controllers,
generators and publicly served static files
![Page 7: Rails Engine :: modularize you app](https://reader033.vdocuments.pub/reader033/viewer/2022051208/547451e3b4af9fbe0a8b577e/html5/thumbnails/7.jpg)
Rails Engine ?
•
![Page 8: Rails Engine :: modularize you app](https://reader033.vdocuments.pub/reader033/viewer/2022051208/547451e3b4af9fbe0a8b577e/html5/thumbnails/8.jpg)
Rails Engine has
Image source: Railscasts.com
![Page 9: Rails Engine :: modularize you app](https://reader033.vdocuments.pub/reader033/viewer/2022051208/547451e3b4af9fbe0a8b577e/html5/thumbnails/9.jpg)
Rails Engine has
Image source: Google
![Page 10: Rails Engine :: modularize you app](https://reader033.vdocuments.pub/reader033/viewer/2022051208/547451e3b4af9fbe0a8b577e/html5/thumbnails/10.jpg)
Rails Engine has
Image source: Google
![Page 11: Rails Engine :: modularize you app](https://reader033.vdocuments.pub/reader033/viewer/2022051208/547451e3b4af9fbe0a8b577e/html5/thumbnails/11.jpg)
Rails Engine has
Image source: Google
![Page 12: Rails Engine :: modularize you app](https://reader033.vdocuments.pub/reader033/viewer/2022051208/547451e3b4af9fbe0a8b577e/html5/thumbnails/12.jpg)
Rails engine walk-through
• Create an engine• Implement requirements in app, lib etc.• Test• Mount to main app• Override where necessary • And done!
![Page 13: Rails Engine :: modularize you app](https://reader033.vdocuments.pub/reader033/viewer/2022051208/547451e3b4af9fbe0a8b577e/html5/thumbnails/13.jpg)
Rails engine walk-through
Create rails plugin new awesome_engine --mountable
Then generate mvc stuffs, test
In App Gemfilegem "awesome_engine", path => "awesome_engine_path
In App Routemount AwesomeEngine::Engine => "/awesome_engine_path", as => “awesome_engine"
![Page 14: Rails Engine :: modularize you app](https://reader033.vdocuments.pub/reader033/viewer/2022051208/547451e3b4af9fbe0a8b577e/html5/thumbnails/14.jpg)
Rails engine walk-through
Hit localhost:3000/awesome_engine_path (mount point)
It will hit engine's root path
Welcome to awesome engine home!
![Page 15: Rails Engine :: modularize you app](https://reader033.vdocuments.pub/reader033/viewer/2022051208/547451e3b4af9fbe0a8b577e/html5/thumbnails/15.jpg)
Rails engine walk-through
Routes:
Use engine routes from main app using engine_name.route_name
e.g. awesome_name.root_path
![Page 16: Rails Engine :: modularize you app](https://reader033.vdocuments.pub/reader033/viewer/2022051208/547451e3b4af9fbe0a8b577e/html5/thumbnails/16.jpg)
Rails engine walk-through
Routes:
Use main app routes from engine using main_app.route_name
e.g. main_app.root_path
![Page 17: Rails Engine :: modularize you app](https://reader033.vdocuments.pub/reader033/viewer/2022051208/547451e3b4af9fbe0a8b577e/html5/thumbnails/17.jpg)
Who are they
• Rails Admin• Devise• Blogit• Tolk• .....
![Page 18: Rails Engine :: modularize you app](https://reader033.vdocuments.pub/reader033/viewer/2022051208/547451e3b4af9fbe0a8b577e/html5/thumbnails/18.jpg)
References
• http://railscasts.com/episodes/277-mountable-engines• http://www.slideshare.net/AndyMaleh/rails-engine-patterns• http://www.slideshare.net/mirrec/rails-engine-rubyslava• http://edgeguides.rubyonrails.org/engines.html• http://edgeapi.rubyonrails.org/classes/Rails/Engine.html• http://pivotallabs.com/users/shagemann/blog/articles/1994-
migrating-rom-a-single-rails-app-to-a-suite-of-rails-engines
Image source:Google, Railscasts and Dulal Khan
![Page 19: Rails Engine :: modularize you app](https://reader033.vdocuments.pub/reader033/viewer/2022051208/547451e3b4af9fbe0a8b577e/html5/thumbnails/19.jpg)
Thanks for your attention :)
![Page 20: Rails Engine :: modularize you app](https://reader033.vdocuments.pub/reader033/viewer/2022051208/547451e3b4af9fbe0a8b577e/html5/thumbnails/20.jpg)
???
Question(s)