Route to separate rack application on heroku? - ruby-on-rails

Lets say I have a Rails app running on Heroku at www.myapp.com. I would like to create a separate Heroku application to serve a simple (Rack-Jekyll) blog for my Rails app but I would like this blog to be accessible at
www.myapp.com/blog/
Is there a way I merge the two apps together considering that they are both Rack based, but keep them as separate Heroku applications and separate git repositories?

You can use redirect method.
match "/blog" => redirect("http://myapp.com/blog")

No, this isn't possible (currently). You'll need to add the /blog as a gem or engine to the mainapp repository, and then push the combined repository to heroku.

Related

Heroku App with a Wordpress Blog

I recently discovered that Heroku now allows PHP which means that a wordpress blog can be hosted on it. I also found this project template: https://github.com/mhoofman/wordpress-heroku
I have a ruby on rails app which is to be hosted on heroku with a domain www.mysite.com, and in that app, i need a way for www.mysite.com/blog to show the wordpress blog.
Can someone help me out, with details on how I can do this?
Whilst I've not used the new PHP platform I don't think what you're asking for is going to be possible.
When you deploy an application to Heroku it detects the type of application during the push process and sets up the application accordingly, Heroku use Apache to host PHP as you can see from the output in this post http://tjstein.com/2011/09/running-wordpress-on-heroku-and-amazon-rds/ - there's not been any mention of mixing platforms in a single application yet so would imagine that it's not supported.
The nearest you'd get is hosting your site and your blog in two seperate applications with the blog on blog.mysite.com and then put a redirect on www.mysite.com/blog to the blog.mysite.com url.
Im Still working on this
the closest to getting a solution is using the reverse proxy gem
see the answer here:
How can I use a subdirectory instead of a subdomain?

How to embed/mount existing Rails app into another Rails app?

I have two Rails apps (using rails 3.0.7), call them "blog" and "auth". I'd like to mount "auth" from "blog" such that I can run the "blog" app and have certain requests routed to the "auth" app.
It seems like I need to embed or perhaps create an "engine", but I'm not 100% sure which is correct.
How can I embed the "auth" app inside of the "blog" app?
You can create "rails-engine" for 'auth' app, and then mount this engine into the rails application i.e 'blog' application.
Read more about Rails::Engine at below links -
http://guides.rubyonrails.org/engines.html
http://api.rubyonrails.org/classes/Rails/Engine.html
To embed a Rails mountable engine into a Rails application, follow these general steps -
1) Open the target Rails project, where an engine should be embedded.
2) Open for editing the Gemfile, and add the following line:
gem '<engine name>', :path => "<absolute path to the Rails mountable engine project>"
3) Open for editing Config/routes.rb, and add the following line:
mount <engine name>::Engine, :at => "/<engine name>"
Rails was raising RuntimeError: You cannot have more than one Rails::Application if you attempted to have two Rails apps defined in one Ruby instance, but it has changed after this commit.
This is still unreleased in 4.0.0, but will get included in the newer versions. (> 4.1.0.beta)
Check out the discussion on PR for more info.
From what I understand, you probably don't need to have two Rails apps, though. You should probably attempt to extract functionality you need in the Rails::Engine.
Remember, Rails::Application is also a Rails::Engine.
You can find a lot of material about how to do it on the web, and I would recommend these two to get you started.
Rails3 is a rack-based application. Rackmiddleware already has a number default built-in applications. Try to run bundle exec rake middleware. You can add custom Rack applications into the stack. Use this blogpost to see how it works.
If auth app is something like a web service (for example facebook authentication), so just keep 2 apps running and make requests from one app with urls to another app.
If these apps share some logic or the same database, you can just merge the code, so two apps become one, or your can make 'auth' app something like a gem or a plugin and use it in your 'blog' app.

How do I develop and distribute a Ruby CLI app with a backing database?

I'm writing a command line program that maintains state in a database. Are there any templates for setting up an app folder structure similar to Rails? I.e. have infrastructure for:
Having all files in lib, app, etc directories auto-required in all of those files
Having multiple database environments like dev, test, prod
Having Rake tasks for runnning tests in a test database
So, this is essentially a Rails layout but without anything to do with serving web-pages.
Once I have this kind of app, I want to distribute it via a gem, but have it initialize a database in the user's home directory when installed, maybe in ~/.myapp.
What would you recommend?
If you just want a gem based application you could look into this guys development here:
http://www.acmesprockets.com/node/24
You could just forgo Rails and using stock ruby with OptionParser and ActiveRecord or Sequel.

Deploying multiple instances of a Rails app - same code, multiple

Firstly, Happy New Year everyone.
I'm new to Rails, so please tolerate any incorrect use of terminology...
I have developed a simple Rails application, backed by a MySQL database.
I would now like to deploy this application to multiple, independent groups of users (i.e. it is a club application, and I would like to deploy it to a number of completely independent clubs).
I would like to use the same Rails Application code as much as possible, and just have a separate instance of the database for each club.
As each instance will be running on the same server (until server load proves to be an issue) I assume I can use a different port for each Rails server to steer users to the correct group?
I'd read that there are test and production modes, is it possible to have multiple [additional] instances of production modes, e.g. club1, club2, all sharing the same code, with unique databases?
My questions are how to support multiple separate database instances, and also how best to route to these?
Any advice on how to go about this much appreciated.
If you are using Git (I suggest you should be!) then you can keep a central version of your code in one place and then deploy it multiple times, changing only the database.yml file (it should not be checked in to your git repository in that case). http://git-scm.com/
Let's say you put all of your code up on github.com with username 'snips' and the project is called 'clubster'. Using something like Heroku you would then do:
git clone https://github.com/snips/clubster.git
cd clubster
heroku create boxingclub
Because Heroku auto-configures your database there is no need for a database.yml file
git push heroku master
And you'd have a version of your code deployed at boxingclub.heroku.com
When you make changes to your code you just go to each of your installations and do:
git pull origin master
git push heroku master
Which updates your code on that particular instance of your application.
And if you're getting a little more advanced you'd be looking at Chef to manage the whole setup for you. http://www.rubyinside.com/chef-tasty-server-configuraiton-2162.html
The other approach would be to have some kind of subdomain system, but I'll leave that to others to cover.

Deploying a RoR application in a separate folder

Let me start by saying I have never deployed a Rails app before.
I have a domain with a main site ran by PHP, let's call it http://www.example.com/.
I have began developing for Rails recently, and I'd like to host the new application I created on http://www.example.com/myapp while still keeping the original site intact.
The main site is hosted on Godaddy.com, but in my understanding they do not support rails well (my application is written in Rails 2.3.5). With that being said, I decided to host my rails app on Dreamhost.com.
So I have two questions: how do I deploy a rails app in a 'folder' on the main domain that actually links to dreamhost. Second, where do I get started with deploying the app?
Thank you!
Personally, I would setup a subdomain on dreamhost: http://myapp.example.com/
Then if you want people to be able to access it via http://www.example.com/myapp, put an .htaccess redirect on your godaddy site:
redirect 301 /myapp/ http://myapp.example.com/
Information on deploying Ruby on Rails on dreamhost's wiki:
http://wiki.dreamhost.com/index.php/Ruby_on_Rails

Resources