Setting up fake URLs locally that support subdomains - ruby-on-rails

I'm developing a Rails 3 app locally on my Mac. I want to test it locally with fake URLs that support subdomains, e.g. http://blah.example.com and http://blah2.example.com. How can I set this up?

Run from your favorite shell and terminal:
sudo nano /etc/hosts
Add this in a new line:
127.0.0.1 *.example.com
Press Ctrl+X to save.
Make sure you do NOT delete the lines that are already there!

Related

Rubymine: debugging using installed Puma-dev?

Is it possbile to have Rubymine connect to (and restart) an installed/running instance of Puma-dev for the debugging session?
I use Puma-dev to test my Rails app on "Appname".test, yet if I need to debug something in the app and want to use Rubymine's built-in debugger, I can only let it start an additional instance of Puma on Port 3000 (or whatever Port I choose) but not the already running Puma-dev on port 80/443.
Is it at all possible?
This is possible with remote debugging. To configure, you have to make some changes to your app:
Add export RUBY_DEBUG_PORT=1234 to .env or .powenv or any file puma-dev will load an environment variable from. Feel free to use whatever port you'd like, although RubyMine uses 1234 by default.
Add the ruby-debug-ide and debase gems to your project's Gemfile.
Add an initializer to your project to initialize remote debugging, like so:
if Rails.env.development? && ENV['RUBY_DEBUG_PORT']
Debugger.start_server nil, ENV['RUBY_DEBUG_PORT'].to_i
end
Restart puma-dev.
Go to Edit Configurations in RubyMine and add a "Ruby remote debug" config. Name it whatever you'd like. Change the port to the port you set via RUBY_DEBUG_PORT. Set your local and remote root folders to your project root.
Select your newly created configuration and click the Debug button. It should connect to the debugger running in your puma-dev process.

I need restart server on production if I want to directly change one line of code on the server?

I have running project ruby on rails on the production server(digital ocean). I only need to add
User-agent: *
Disallow: /
I don't want to push to the repository and update it on the server. I want a direct change on server robot.txt. Question: I need to restart the server? If yes, which command do I need to run for the changes to take effect?
You can login with ssh credentials. Go to your file location and open it like this:
vi robot.txt
insert your changes and restart apache server like this:
sudo service apache2 restart
Just edit the public/robots.txt it is a static file, no need to reload a server.

How to Move A Ruby On Rails Website To New Server

I have a Ruby on Rails website which I have successfully tar the apps directory which included the current folder ect. Which I Wget to transfer the files over. The server I have moved to is setup to run Ruby on Rails but is there anything else I need todo to get it running?
Any commands via SSH?
My new server setups is Ubuntu 11.04 running ISPConfig 3 as the server admin.
Current the file are in the correct location with the correct permissions and owners. But all I'm getting is the default ISPConfig page.
(This is the default index page of your website.
This file may be deleted or overwritten without any difficulty. This is produced by the file index.html in the web directory.)
If anyone can point me in the right direction that would be great.
Have you tried creating a symbolic link on the server to the application something like
cd ~/public_html;
ln -s ~/rails-test-application/public rails3
http://www.site5.com/blog/programming/ruby-rails/how-to-deploy-phusion-passenger-to-a-subdirectory-routing-errors-and-restarting/20090414/

How do I get subdomains to work on my local machine?

I cloned a repo and am trying to get it to work. The app is very heavily dependent on subdomains. For example, signin.app.com or company1.app.com.
However, since I am trying to get it to run on my local machine, I can't simply do signin.localhost:3000
So, how do I get these subdomains to work using localhost?
Thanks!
As Gene said,
/etc/hosts file:- (add)
127.0.0.1 subdomain1.localhost
And on Rails3 this is treated as a domain, so you need to just add this:
127.0.0.1 subdomain1.localhost.local
then try,
http://subdomain1.localhost:PORT
In linux
open command prompt
>sudo vi /etc/hosts
Add a line in file
127.0.0.1 subdomain.hostname.com
and press Esc and :wq (means save host file)
thats it you type subdomain.hostname.com in your browser. Subdomain will run in localhost.
You could add the domain names to your hosts file, routing them to localhost.

How Can I Load localhost:3000 in Chrome On Issuing A "rails s" Command?

My workflow looks like this:
$>mate .
Edit stuff using textmate
Go to command line to run $>rails s
Go to Chrome to click a bookmark that loads localhost:3000
View the app
Load text mate to fix/revise
Back to command line to git
Repeat
Is it possible to rig step 3 so that it will also load a new tab with localhost:3000 in it? One less click, saved many times.
Since you're using TextMate I'll assume you're on a Mac.
Two things you can do.
Setup Phusion Passenger on Apache (Mac OS X already has apache) so you save yourself the rails s. You can find tutorials on this at many location. But basically you follow the instructions from the Passenger website and then install the Passenger PreferencePane to make your life easier. To do this you'll need the XCode installed.
Start the rails server in the background then calling open to open the URL
#!/bin/bash
#
# save this in script/start.sh
# don't forget to do chmod +x script/start.sh
rails s &
sleep 4
open http://localhost:3000
In addition to the recommendation for Passenger above, I'd also add that you can install the "Passenger Pref Pane" that will let you easily add projects and set their environments (production/development).
Passenger + Passenger Pref Pane will completely eliminate the need for rails -s, with minimal fussing on the Apache config files.
I think Textmate also allows you to do some scripting that might even get you to be able to launch and open the url in Chrome on save, but I haven't ventured into that area of Textmate yet, and it would probably take more work than just hitting refresh after the save.
If you don't mind adding some code, you could put this in your config/application.rb:
config.after_initialize do
if Rails.env == 'development'
system('open /Applications/Google\ Chrome.app http://localhost:3000')
end
end
That will open a new tab each time though and if this is a multi-person project, you may get complaints.
Another option would be to look at live-reload to get the tab to refresh when a file changes. Even without Passenger, on Rails 3 I rarely have to restart the server, so just reloading the tab might make more sense.

Resources