Ruby on Rails app in root directory? - ruby-on-rails

Hey guys, new to rails, but I have found out how to create an app now through the shell but to create an app using rails appname would give me a url of http://url.com/appname/ but I want my app, to be within the route if you understand me, so it's just http://url.com/login/ or /signup or /play so on?
So does anyone have any ideas how to do this, or why you can't or I shouldn't? Anything really, thanks guys!

if you use passenger and apache, firstly in your apache conf file
<VirtualHost *:80>
ServerName myapp.local
DocumentRoot "/home/davit/myapp/public"
</VirtualHost>
DocumentRoot should be point to your app' s public folder.
And in public folder create a .htaccess file and write this:
PassengerEnabled on
RailsEnv development

Rails application is stored in some directory like appname but it doesn't appear in url path. In general you should configure your server (Apache, nginx, ...) to point to public folder in rails application. The only thing to do is to configure your server properly.

It depends on your hosting provider, with dreamhost, which I use, its part of the tools they provide to configure where do I want the application to be.
If you have to configure things yourself, you can still write your alias configuration or whatever your server uses to map to your rails application public/ folder.

Related

How to change the configuration file to deploy a rails app with apache? on a subdomain

I was given an url http://XXXXXX.XXXX.XXX/avrccalendar/
and was asked to deploy my rails app on it.
At the beginning, there was a static webpage index.html in the /www directory, which is nothing but a message and was deleted by me.
This is my first time to deploy a rails app and I set my .conf like this:
VirtualHost *:80>
ServerName XXXXXX.XXXX.XXX/avrccalendar
DocumentRoot /home/avrccalendar/calendar/public
RailsEnv production
/VirtualHost>
I set it up that way, because I think rails app creates dynamic content, thus I didn't put the app files in the /www directory. However, when I visit the website it still get the static webpage index.html.
I cannot find whers the configuration is that set the url to return that static webpage.
And i would like to know how I should set .conf to make it to visite my rails app.
I have already installed passenger. The environment is Ubuntu 14.04.
Any advice would be helpful. Thank you~!

How to serve an api subdomain using apache, passenger, and rails?

I created a subdomain like the following myapp.example.com and it works great ...has been. Now I want to build an API using rails for the app (rails itself) so I created the subdomain api.myapp.example.com. Currently the problem I'm getting is the api subdomain isn't getting routed to the rails app.
I tried adding the following to the apache conf file in /etc/apache2/sites-enabled/example.com.conf
# example.com.conf
ServerAlias *.myapp.example.com
I then restarted Apache, but still api.myapp.example.com wasn't being routed to rails application.
Ahhh, it ended being an easy fix
# example.com.conf
ServerAlias myapp.example.com api.myapp.example.com

How to use geminabox with Apache web server

I want to use geminabox with Apache web server. I have searched a lot on web but could not find any concrete information. Can some one please let me know how to do this ? Will appreciate detailed suggestions.
An easy way to use Geminabox with Apache is to configure a HTTP Reverse Proxy.
For this configuration, you just need two files:
1) The config.ru just like the example in the README.md file in the geminabox repository:
require "rubygems"
require "geminabox"
Geminabox.data = "include here the data path"
run Geminabox::Server
To run the server use rackup command. This will start the server in the 9292 port. If you want to change the port number use rackup -p XXXX.
2) In the Apache side, make sure that you have the mod_proxy and the mod_proxy_http installed. If yes, just include the following lines into your Apache config file:
ProxyRequests Off
ProxyPass / http://localhost:9292/
ProxyPassReverse / http://localhost:9292/
Restart the Apache and it is done!
geminabox is a ruby application, and just like all ruby applications, Apache does not support them out of the box.
With that said, a simple Google of how to use ruby applications with Apache lead me to this, which lead me to this. I have no experience with this tool. However, it is suggested by the rails team, so it has to have some merit.
I did work with Apache VirtualHost.
In folder /etc/httpd/conf.d/ create a file gems.conf, so add it to the file:
<VirtualHost *:80>
ServerName gems.mydomain
ServerAlias gems.local
DocumentRoot /var/railsapps/gems/public
</VirtualHost>
Where /var/railsapps/gems is the folder that have the config.ru.
The domain gems.mydomain must be in your DNS or /etc/hosts

Apache and rails

guys.
OK. Trying to deploy a rails project on apache. Ive deleted the public/index.html file. I cant get past the "It works!" screen. Im guessing this is a routing issue - Ive got to give it the right document root so that it can find the homepage of the app I have created, right? Problem is, Ive tried everything - anything outside of the public folder doesnt seem to exist. Here is my apache sites-available file:
<VirtualHost *:80>
ServerName localhost
ServerAlias localhost
DocumentRoot /home/feenix/public_html/CRRC/public
</VirtualHost>
I changed the rails root to "home#index". Ive tried that as a document root for apache and it doesnt recognise it. Any help would be appreciated, as to where I should be looking for the correct document root - do I have to add something to the public folder in the rails project? Any help will be gratefully appreciated.
Cheers
It works! is the Apache default. That means you aren't pointing properly at Rails yet.
You've got the DocumentRoot correct.
Do you have NameVirtualHosts *:80 setup? Also, is Passenger enabled? I'm assuming you're using it.

Create/Modify a Virtual Host and Reload Apache from Inside Rails App

My application is a set of two rails applications. Based on some parameters in first app. I need to setup the virtual host of the second app. I just need to change the ServerName and ServerAlias in apache VH and enable the site using a2ensite and then 'apache2 reload '.
How can I do this from within a rails application?
Thanks,
Imran
First of all: be aware that enabling web-apps to change the server configuration is a security risk.
# First, open the config file
fd=File.open('/etc/apache2/sites/yoursite', 'r+')
# read in the contents
content=fd.read
# now replace the ServerName and ServerAlias lines with your new setting
if content.gsub!(/ServerName(.*)/,"ServerName NewServerName") and content.gsub!(/ServerAlias(.*)/,"ServerAlias NewServerAlias")
fd.rewind
puts "\tsaving file"
fd.write content
end
fd.close
I did not test neither code nor the regular expressions, please load the relevant parts of your config file into rubular.com and roll your own regex.
Maybe you should also make a backup before saving using
File.copy(file,file+".bak",true)

Resources