Rails app to engine - ruby-on-rails

How we can convert a existing rails app(3.2.11) into a engine. We have some defined functionality in our rails app and we want to use this rails app functionality as engine so that we can add/share/mount this functionality with other rails app.
Do we have any available gem or any idea for this.
Thanks in advance!!

We have recently started doing this at my company and we will never look back. Engine gems are great for using the same logic across multiple projects.
That said, start with this railscast: Mountable Engines (I think this is the right link, it is blocked here at work so I can't verify for sure. If it's not then just google "railscasts engines.")
Also, check out the documentation here.
This is where we started and we released our engine in no time.

Related

How to make a blog application that plugs into other rails applications?

I want to have a blog functionality for some of the applications I have, Instead of developing and maintaining them as part of each application, I would like to develop a blog application and plug it right into other applications and maintain a single code base.
What approach should I take to accomplish this? Or Is there a gem that already does this?
Thanks.
A Rails engine sounds like your best bet. An engine is an application that provides functionality to its host application. Getting Started with Engines guide is a great place to start and just so happens to guide you through the process of creating a blog engine. There are such engines that exist in the wild, such as Blogit. Whatever you decide, running through the engine guide would give you a good understanding of how engines work.

Embed Blog in Ruby on Rails

I have a Ruby on Rails application and want to include a blog inside the application.
I was wondering what's the best way to do that. I don't want to have a link to an external blog. I want the blog integrated in my application. Also i don't have the time to programm the blog functionality. I want to use existing solutions.
What's the best way to accomplish that? Any recommendations? What are the best solutions?
The best way to include one application within another is by using engines. This might help you Ruby on Rails 3.1 Blog Engines
Perhaps Typo would address your needs installed as a Rails Engine.
Since nobody has done it so far I need to mention here that the spirit of Rails is to make everything friendly enough so that you can code your own.
It's a bit more work but then your blog module fits right in with the rest of the app.

Ruby on Rails 3.1 Blog Engines

I see a lot of people asking about Blog Engines, but most of the questions & answers are rather old. Or if they aren't old most of the projects are old. I'm wondering if anyone knows of any Blog Engines that currently support Rails 3.1 or are at least being actively developed to support Rails 3.1.
I would also be interested in seeing any sample applications or blog posts written for Rails 3.1 Blogs. I am going to be adding a blog to one of my websites, and would prefer to simply use a Rails Engine or sample code if there are any good ones out there. I hate reinventing the wheel. Looking for something simple, and not too opinionated so I can modify easily to suit my own needs.
you might want to check out Refinery http://refinerycms.com/engines
doesn't look like they are 3.1 yet, but probably soon
https://github.com/resolve/refinerycms-blog
Your best bet would probably be to use Typo.
Typo is currently using rails 3.0.9. Rails 3.1.0 is still a release candidate so I don't know of any blogging apps using it right now. If you must use rails 3.1.0 then you may have luck grabbing the gem for 3.1.0.rc4 (the newest version) and using typo anyway. Chances are everything will still work.
Hope this helps.
Perhaps Enki is a good fit, currently at Rails 3.0 but there is a github branch with Rails 3.1 support.
http://www.enkiblog.com/
Interestingly BrowserCMS was recently made to be a mountable engine: https://github.com/browsermedia/browsercms/commit/6098699fed2e3dbd65815ac3a5ce0dd6acc103d2
Seem to have a bit of time and experience behind them. More akin to Concrete5 with an inline front end / in context editing facility for users, which can be a real plus.
Im looking into this now and Im getting to conclusion that the best way to do this would be mounting a rack-app(like sinatra) into your rails app, there's various basic sinatra blogs in github to start or copy, not to mention this is fully customizable and I guess very light-weight.. engines will likely have dependencies and may also break when updating gems, a rack app won`t
I wasn't able to find any satisfying solution with engines
other stuff I found:
mounting a rails app inside a rails app: http://blog.dynamic50.com/2010/02/22/rails-3-0-mount-multiple-apps-as-engines/ feels a bit weird(heavy?), but you could mount a fully featured app like enki...
http://planscope.io/blog/2012/03/08/mounting-a-blog-within-a-rails-3-application/ this blogpost talks about using Toto, it seems pretty nice, easy and simple... but the project is not being maintained and it doesn't seem to be able to support a lot of features...
I dunno about using git to post, it makes it really simple but I dunno if I'd like having non-code stuff in my commits
Monologue https://github.com/jipiboily/monologue . From their web:
It is a barebone blog engine for Rails. It is built as a Rails engine and with a focus on keeping very few dependencies to ease it's use in your project. You can also use monologue-markdown which will replace the default editor with a simple Markdown editor.
Seems like pretty active development also.

Is it possible to create sub-applications in Ruby on Rails 3 or something like slices from Merb?

Does Rails 3 have anything akin to slices in Merb, or areas in Django where there is a layer of organization above the controller? I heard at some point that they may allow hosting one rails app within another but I can't find any information on that in the pre-release material. Any hints on how to do something like this?
You're right there doesn't seem to be a lot of official documentation on it yet. But yes, you can have application slices -- they're called engines in Rails. Actually they've been available in Rails since 2.3. Currently, you basically make a plugin that has a complete application structure and set up your routes in there to "mount" your app against a specific URL. In Rails 3, engines are basically first-class objects in the Rails stack. I believe they can still be plugins but you will also be able keep it away from your application in a separate gem and require it in your application much more easily. You should be able to find stuff pretty easily on teh Google, but here's an oft-linked but informative reference: https://gist.github.com/af7e572c2dc973add221

Extracting a Rails application into a plugin or engine

I have a Rails 2.3 application which I would like to extract into a plugin, or engine. The application has user authentication, and basic cms capabilities supported by ancestry plugin.
I want to extract the logic for the application into a plugin/engine so that I can use this code for future projects, with a different "skin" or "theme" if required.
I'm not entirely sure I actually understand the difference between plugin and engine concepts, so that would be a good first point.
What is the best approach, are there any good starting points, links, explanations, examples that I should follow. Also, with the release of R3 to consider, is there anything that I should be aware of for that, with regards to plugins etc.
I am going to start off by watching Ryan's http://railscasts.com/episodes/149-rails-engines
but obviously thats over a year old now, so one of the challenges I'm faced with is finding the most up to date and relevant information on this subject.
All tips and help gratefully received.
Actually, converting an application is pretty straigtforward. Just create a plugin-folder, put an app-folder inside containing all yor model-views-controllers folders, and that's it.
You will have to manage your migrations yourself though. Also you have to define rake-tasks to copy files to your public folder. I think the railscasts is still pretty up-to-date, if anything it is now easier in rails 2.3.
Good luck!
[EDIT: for rails3] Rails 3 engines are very clean and powerful. Check this gist by Jose Valim.
You will probably be better off focusing your engine on Rails 3, as opposed to trying to make it compatible for Rails 2 and Rails 3, due to the backwards incompatible changes. Here is a more up to date tutorial for Rails 3
also the book "Crafting Rails applications" by Rails Core member Jose Valim, has a good chapter on it. Int he shows how to use his tool EngineX which generates a Rails 3 engine structure, so you can more easily create engines for your Rails 3 projects. His gem devise is also a rails engine which is also nice, because you can easily customize it by copying the templates into the application directory, and allowing you to subclass the controllers that you want to customize more.
Writing a plugin is an entirely different process than writing an app, if you already have your app code it should be straightforward converting it into a plugin.
Consider that if you use third-party plugins in your app it could get pretty messy.

Resources