Merging two rails apps - ruby-on-rails

I have a main app and a forum app. I wanted to include forums in my main website. I manually copied all files from forum into my main app. I created proper routes and copied everything from db/migrate.
Now, I can see that everything is included and it works. But the problem is that whatever was originally stored in my forum apps that is questions and categories are no longer stored in the main app after merging. Its like a new copy.
Is there a better way to merge two rails apps along with stored data? or is there any way i can resolve this issue

You can adapt your forum application as a mountable app, follow this tutorial. I think this could be the best way to do that.
Also you can read pointers in this my previous question to get a general idea on rails engines: Differences between railties and engines in Ruby On Rails 3

Features like forums which are common across web apps can be built using engines which can be easily plugged into rails apps
If you want to share the data between 2 rails apps, you have to have a separate setting in database.yml and use establish_connection method inside the forums model in both the rails apps.
Click here to understand how to configure multiple databases in a rails application.

There you go:
https://github.com/adamwiggins/yaml_db
Install the plugin
rake db:data:dump
from the old database
rake db:data:load
to the new database.
Voila!

Related

How to automate rails project "bootstrap" consolidating routine customizations?

As we create more Rails applications, I find myself routinely adjusting the project generated by rails new ... in exactly the same ways: adding rspec, capybara + capybara-webkit support, adjusting config/application.rb to our tastes, including several gems we came to love.
I had a look at suspenders, it's a good starting point, but some of their choices differ from ours. Plus it's flexible in places where we don't really want any choice. In fact we'd rather have a couple project boilerplates sharing some customizations and each adding some unique extra's.
What are the options for streamlining/automating a project "bootstrap"? How could we organize a set of boilerplates and let them evolve as our preferences change (not adding options, but changing which made choices are hardcoded)?
I'm thinking in the direction of scripting what I normally do manually starting from rails new, editing the Gemfile, config/application.rb etc, but may be there is a cleaner (future versions compatible) approach or tool?
I really like using the Rails Composer gem/tool for this.
At the basic level when you run Rails Composer it will ask you a series of questions about what gems/configuration options you'd like your new Rails app to have. Then generates your app for you.
I like the "ask me for what I want" approach because different Rails projects may need different things: Postgres vs MySQL, Bootstrap vs Zurb Foundation, etc. 90% of these are usually the same, but it's the 10% difference that gets me.
At the more advanced level, Rails Composer shows you how to use Rails templates to create your own standard modifications, or you could fork Rails Composer to add the options you want (maybe sending a PR back to the project if it's something useful?)
At the expert level, Rails Composer has "starter apps": just pick one of those and go, choices already made for you. Depending on your needs this might be just the kind of thing you're looking for -- digging into how these "starter" apps are created and making one yourself.

Allow user to configure Rails application for first use (ActiveRecord etc)

Before I start the process of building something from scratch I was curious if anyone else had come across a way of providing a first-time configuration wizard for a Rails application that allows the user (sysadmin) to configure aspects of the application such as the ActiveRecord configuration and the ActionMailer setup (SMTP, sender etc).
We'd like to provide a clean easy way for new installs to get setup, rather than asking clients to edit files, or run scripts on the command line.
Essentially you should be able to download the application, extract it, start it, and when you access it via the browser you're guided through the initial setup steps.
My question isn't so much around how to do this, but more has anyone already done this. My quick search for gems, plugins etc around this idea didn't turn up much.
Edit/Clarification
To clarify the scenario - this is to support "shrink-wrapped" products that are downloaded and installed on-premises by the customer's sys admin.
The first time they access our application after deploying it behind their firewall we want a friendly way of configuring the specific settings for their install, such as database etc.
An example of such a process is JIRA's setup wizard:
https://confluence.atlassian.com/display/JIRA/Running+the+Setup+Wizard
This isn't for reating new rails applications, or systemising our development process.
I like Rails Templater a lot. It is a command line tool to build a rails app. It asks you questions like "Would you like to use rspec? Pry instead of IRB?"
I have created a fork that adds authentication, twitter bootstrap and backbone.js and some other options. It is pretty easy to hack on if you have specific needs. I use it all the time and I would hate not having it.
It is of course a command line app and not usable via the browser but maybe it will still fit your needs. Or the codebase could be integrated into a client web application.
Update after comment
You may be able to bootstrap a sqlite database so the app can boot, then just using a form or a wizard to set up something that writes your database.yml and other configs, maybe by means of thor (makes appending/replacing text in files simple and is part of rails). You would need to somehow restart the rails app and migrate the database. You could keep the pg or mysql2 gem (or both) in your Gemfile or again use thor to edit them from your wizard/form.
I also recommend using rails_config as Michael suggested. With the above solution.
If I had more time to think about the problem, I may come up with something cleaner but this is how I would do it if I had to right now.
http://railswizard.org/ lets you select which gems to use. It's a very innovative use of the ui and the isotope gem to select the components. Similarly another viewpoint is this top 10 list: http://blog.teamtreehouse.com/10-must-have-ruby-gems
You'll never find a definitive list of gems as need change from person to person and over time, e.g. which database your company uses and which is the 'current' best authentication gem are both variable.
For configuration specific settings you can make the configuration less of a chore by using practices that reduce it. For example the database.yml file is usually one of the 'must be edited locally' files. Our approach for this to to exclude database.yml from source control by putting its name in our .gitignore file. We add an database.yml.example file which we copy locally to database.yml and in that file we use anchors (&) and references (*) as detailed here: http://blog.geekdaily.org/2010/08/advanced-yaml-tricking-out-your-databaseyml.html
More options for configuring other variables for each environment: http://kpumuk.info/ruby-on-rails/flexible-application-configuration-in-ruby-on-rails/
The rails config gem may also help you as detailed here: How to define custom configuration variables in rails

Why rails doesn't want you to create rails projects within existing rails project

I want to create another project inside exisiting rails app. My reasoning is that:
They have some common models which I would be able to link to from the inner app,
They operate on the same database
They will have one version control system (no additional configuration and moving required)
Apart from why I want to do that I just want to know why rails prevents you from doing that? As of my testing, no conflicts were exposed.
You should be using Rails Engines for this. Here's a Railscasts episode about it. http://railscasts.com/episodes/149-rails-engines

Well built rails code for download

I want to get into rails by examining well built code
where can i find typical open source rails project that i can download
and learn from ?
i'm interested in facebook connect integration (facebooker), tag clouds, searching in
my website
I'm not looking not tutorials or screen casts
Thanks!
This question gives a good list
a list of projects with good test-suites
a list of open source rails apps to learn from
Have a browse of ruby tool box and download some open source. For example there's refinery and zena, two content management systems and Rboard, a forum. Depends what you want really but there's plenty out there. Ruby toolbox entries are ordered by github watchers and forks to give you an idea of their popularity.
I really like looking at the commits in teambox.
I find it a bit more complicated. But there's also spree.
There's also devise which is really interesting to look at too.
Finally, I'd recommend you to follow the rails commits (it's the only commits feed I have in my Google Reader).
Gady, this is an extremely rich topic you're asking about and resources are all over the internet. Try starting at http://rubyonrails.org/.
You should be able to find tens of questions just like yours (asked and answered) by searching SO at the top bar.
For Rails, part of it is the building process, so one feasible approach is to read a tutorial like http://railstutorial.org/book
then when in Chapter 2, you will use Scaffold, and at that time, you will have some basic code to look into how a basic Rails app is.
I also suggest you use source control like Git, Mercurial, or SVN to commit different phases of the project, from creating the rails project and then after each step, so you can diff what the changes are during each step.
If you already have Ruby 1.9.2, Rails 3.0.1, and sqlite3, then you can
rails new myproj
cd myproj
rails generate scaffold foo name:string salary:integer gpa:float note:text
rake db:migrate
rails server
and now you can use http://localhost:3000/foos to create, display, update, delete the foo records, and have quite a bit of source code to look at. Most of the customizable code is in app, with css and javascript in the public folder.
Ryan Bates has an excellent series of videos.
http://railscasts.com/
An extremely valuable resource.
Radiant is a CMS that you can download for free and see how it works. It is a great piece of code to look at and see how it works.
I guess that most open source Rails projects are shared on Github, so it may be interesting to browse its Ruby section and look for most watched or most forked projects:
http://github.com/languages/Ruby
Steady stream of new interesting projects to take a look at :)
And don't forget the official:
guides.rubyonrails.org
well there is one "bigger" project on github, waiting for downloading and contribution...
but it's a little controversial because of the security issued they have (had?)
It's still worth a look:
http://github.com/diaspora/diaspora

Building an extension framework for a Rails app

I'm starting research on what I'd need in order to build a user-level plugin system (like Wordpress plugins) for a Rails app, so I'd appreciate some general pointers/advice. By user-level plugin I mean a package a user can extract into a folder and have it show up on an admin interface, allowing them to add some extra configuration and then activate it.
What is the best way to go about doing this? Is there any other opensource project that does this already? What does Rails itself already offer for programmer-level plugins that could be leveraged? Any Rails plugins that could help me with this?
A plugin would have to be able to:
run its own migrations (with this? it's undocumented)
have access to my models (plugins already do)
have entry points for adding content to views (can be done with content_for and yield)
replace entire views or partials (how?)
provide its own admin and user-facing views (how?)
create its own routes (or maybe just announce its presence and let me create the routes for it, to avoid plugins stepping on each other's toes)
Anything else I'm missing?
Also, is there a way to limit which tables/actions the plugin has access to concerning migrations and models, and also limit their access to routes (maybe letting them include, but not remove routes)?
P.S.: I'll try to keep this updated, compiling stuff I figure out and relevant answers so as to have a sort of guide for others.
You might want to check out mephisto, it's a blogging software built with ruby on rails and has add-on plugin support. Not sure if it works how you are thinking of, but might give you some good insights. The source can be found on GitHub.
You should look at deface gem. It allows to customize rails views, adding content via hooks and replacing whole views/partials. Spree is using this gem so you can look also at spree. Beside views they also have other solutions for customizing application so you can find more answers to your questions.

Resources