Setting up Ruby on Rails for web development - ruby-on-rails

I was considering installing, setting up and using Ruby on Rails for web development. Where should I start and how does Ruby on Rails work with a local server? Any OS where Ruby on Rails is optimal or any general advice I should know?

Any OS where Ruby on Rails is optimal or any general advice I should know
Linux and Mac OS are by far the most popular dev OS's for Rails - you can install dependencies much easier.
Windows can be a real pain with Rails at first. Not rails, but its dependencies. These are called Gems and work like plugins.
Certain gems require external binaries / C headers for them to run. Two of the most notorious are the MYSQL2 and RMagick (ImageMagick) gems.
--
I don't know the core problems (it's something to do with MINGW32 / Win32 environment), but Windows often has a difficult time with certain gems.
Not that it's stopped us - we have a series of Windows machines devs use to create truly incredible RoR apps (very difficult to get them all running smoothly).
DB
You don't get a DB with your Rails install - you need to have that running separately.
If you don't want to install a local MYSQL server (which can be a pain), I'd recommend getting some cheap shared hosting (with unlimited MYSQL db's). This will allow you to hook up your app to a third party DB host, negating any data integrity issues if your dev machine has problems.
Make sure you have PHPMYAdmin too - it's a life saver :)
Although Rails with many different SQL variants, MYSQL is the most popular. Heroku has made PGSQl quite popular within the Rails community, although I'm not up to speed on the major differences.
how does Ruby on Rails work with a local server
Rails comes with its own web server for development, called WEBrick.
Honestly, WEBrick is a pile of shit but it works.
You just need to load up the cmd, type rails s and it will fire it up. If you get some more experience, you can use the likes of puma or thin as dev servers (they are much faster and better mimic the production environment)
In production, you'll be best using one of the commercial-grade servers like Apache or NGinX, good tutorial here.
Getting Started
There are a ton of tutorials to get started with Rails.
Some of the best resources are:
RailsCasts (stopped mid 2013)
GoRails (still active)
Michael Hartl Rails Tutorial
Finally, enjoy yourself. I remember the Tumblr guy saying that he got such initial traction for Tumblr through the Rails community (he said they're the most committed bunch ever). He was right, the Rails community is a big family who all love code.

Download Rails from http://railsinstaller.org
go through online tutorials and start working
it a beautiful language to work with

Related

Backup CentOS Webserver & install it on local machine

I was wondering if it was possible to make a complete backup copy of a CentOS Web-server and install it on a local machine.
I am new to Ruby on Rails and find it difficult to program without erroring out the complete server. so i would like to make a seperate server that i can use for development porposes
Godaddy.com VPS ultimate server CentOS 6.4
ruby 1.9.3
RoR 3
Nginx
Postgras SQL
To test a server, using it's own operating system etc, on your own local machine, you should look into Vagrant. http://www.vagrantup.com/
There's a lot to learn, and to be honest, while you're learning, you may want to consider an easier option for deployment, such as https://www.heroku.com/ or https://ninefold.com/ and then worry about figuring out how to set up a server by yourself once you're more experienced.
If those options are too expensive, you could consider https://www.digitalocean.com/ - you can create / destroy servers easily, and if you pick their pre-built ruby on rails server (under applications tab, when you get to that step), you'll save yourself some pain.
Lastly, if you decide you really want to learn how to set up a server for rails, you should look at this book: https://leanpub.com/deploying_rails_applications
You'll save yourself a lot of time and frustration by learning it all once, properly and thoroughly, than by learning it ad-hoc by solving error after error.
But again, if you're new to rails, I'd really recommend something like Heroku to take ther server setup off your hands and let you focus on learning rails itself.

Most stable (headache free) development environment for Ruby on Rails?

Would some of the more advanced rails developers please share what they have found to be the most productive combination of OS, IDE, etc. (i.e. the set-up that gives the least of amount of compatibility issues, headaches)? Also, what is the most commonly used setup?
I presume the common setup is common because it is thought to be the best compromise between all the options.
And that common setup is:
Mac OS X
TextMate
rvm
There's a lot of nuance to your question, for example you'd probably want to take into account what you already have, what your appetite is for spending money, etc. This is before even coming to the minefield of personal preference. :)
Here's a starter list:
Operating System
In my experience on both, Mac > PC for Rails programming because it creates fewer unforeseen/annoying problems.
IDE
Depends on how 'rich' you like your environment to be. Some people who like light environments simply use Notepad++; others use richer options like TextMate (Mac only) or RubyMine.
General Set up
Rails 3.1, MySQL
Local Server
Webrick and Mongrel are fairly popular.
Hosting
Heroku is extremely popular for Rails apps. It's free for low traffic and they're beautifully designed for Rails. If you want to avoid the server reloading problem (webpages take a while to load if no one has requested them in a while), you can set up NewRelic or Pingdom to ping the app and keep it active.
Performance Monitoring
NewRelic
I moved from Windows for Rails 3 to a Ubuntu 11 virtual machine running on Windows via VMWare player.
I'm using Gedit along with GMate (source here) to make Gedit more similar to TextMate for Rails Development.
I've found the setup to be way faster running on the virtual machine than it was on Windows directly. It took some time to get set up but once done, I just transfer the vm image from machine to machine. The setup was all free too (besides my laptop and the copy of Windows 7 on it).
The most common development environment I suspect you'll find among the Rails illuminati is probably:
Mac OS X (though some use Linux)
various Ruby versions/gemsets in RVM
TextMate or MacVim as the IDE (gvim or vim for the Linux folk, usually, though some prefer Emacs)
SQLite or MySQL for development database
Webrick, Mongrel, Thin, or flavour-of-the-day lightweight local webserver

Ruby on Rails development on windows

I've been planning on developing a rails project on windows.
I've heard that the framework wasn't tested on windows (at least not the testing framework)
does anyone have any real experience with rails on windows?
are there any known bugs when running on windows?
does the testing framework work on windows?
I've been developing a Rails website on Windows & Mac (depending on where I am at the time) for a few months now and, in general, I haven't run into to many problems. Here's what I know:
The new Ruby 1.9.3 installer for Windows is nice because it comes with RubyGems (which a vague memory tells me was difficult before). That's what I'm using. I haven't been able to get the ruby-debug19 gem to install correctly on windows. So, I just comment that out in my Gemfile on my Windows computer. Other than that, I haven't had any issues.
With that said, however, I love developing on my Mac so much more than I do on Windows. I haven't found an editor that I love for Rails development on Windows (currently using Sublime 2 or Notepad++ with Explorer plugin), using Git is not as nice on Windows, and I just really don't like the Windows Command Prompt (I know there are other options, but still).
I have recently been working with another developer that has been developing on his Windows laptop. He's been using the same tools and Rails 3 codebase as myself (I'm on Mac OS X).
He has had a number of blocking issues that have wasted many hours of his time - for example he hasn't been able to run any of our RSpec tests, and some Rake tasks.
Getting the environment setup is a pain, and even when you do, it's stressful because you never know when you are going to hit the next bizarro Windows-only bug. The reality is that Windows is a rare OS among Rubyists, and even if that wasn't so, the Rails framework developers themselves are UNIX-oriented, so there is an order of magnitude less scrutiny given to testing and development on the platform.
What's more, many of the sweet tools in the Ruby world are command-line and they work better in a real POSIX shell.
My co-worker has now bought a MacBook, and is enjoying a smoother development experience again.
But you don't need to buy a Mac; You would do just as well with dual-booting into Ubuntu (Or similar) on your existing laptop.
I prefer developing Rails with the help of Vagrant and some Chef cookbooks to create a virtual machine where I run my Rails code on. This solves the problem with some gems not working on Windows and seems to be faster. Here's a post a wrote how I got this working
I've tried 5 different ways to setup Rails development environment on Windows.
These includes virtualized Linux environments, Windows subsystem for Linux and alternative Ruby interpreter like JRuby. Rails on Ruby MRI works relatively well, but certainly there are gems that build native extensions that cannot be compiled on Windows. Depending on which gems your project requires, you might have a easier time.
I've got a short comparative write up here http://cs.mcgill.ca/~mxia3/2018/02/18/Five-different-Rails-development-environment-on-Windows-10-and-their-pros-and-cons/
I have been developing on Windows using Ruby (currently 1.9.2), Rails (both 2.3.x and 3), Rspec (1.3 and 2), Cucumber, Capybara, selenium-webdriver, sqlite3 for a few years now, and it all works most of the time. The company I work for deploys a Rails app on Linux and Windows along with our other piece of enterprise software.
That being said, I do run into weird issues a lot. I'm now trying to blog about them so that they're googlable and, eventually, I'm trying to learn how to fix them. Ruby Windows support has improvements to be made, for sure, but no one will bother fixing them if no one is using Ruby on Windows!
Definitely use the RubyInstaller. Luis Lavena, one of the main contributors, is really nice and responsive on the RubyInstaller mailing list and twitter.
I would not use Ruby on Rails on Windows for a production website, but it is commonly used for development, in particular by designers that need to work with RoR teams. We developed and use internally with our designer guy Rubystack, which is a free, all-in-one installer that setups a Rails development environment in just a few minutes.

Why is it supposedly "hard" to deploy Ruby on Rails to production?

I admit that I don't follow much of anything "right" on deploying test versus production code. I have been using ASP.NET, and I typically run it locally in Visual Studio, it works, I upload it, I test it again on the production server.
I have read several people say that deploying Rails apps is harder and there are special programs/ways on the ruby site about deploying RoR. I've only toyed with RoR. What is special about deployment? You don't just copy and paste the code and run it (from development machine to the production)? Is it because one is in Apache and the other running on the built in server?
This will be on a Mac Server if it matters.
Deploying RoR is not difficult anymore, especially with Phusion Passenger.
What is somewhat difficult, is getting a automated production environment setup with capistrano, vlad, etc. If you don't mind simply copying your code to the server, you can do that just fine. Most people choose not to do it that way because you lose out on a lot of the benefits that the automated deployment tools give you.
I guess people consider a Rails app harder to deploy than say some PHP apps or such where you just plop the code somewhere and point Apache or whatever at it. But, as mentioned above, you could do that now with Phusion Passenger.
We use Nginx+Passenger, but not for simplicity of deployment. Capistrano is our deploy tool of choice, and really, unless you have a very simple app, you're going to want something like Capistrano anyway. For example, with our deploy, we do a slew of things:
run any database migrations
generate release notes automatically, based on all the commits to Git between the last deploy and this one
notify various people via email (with differing lists depending on whether the deploy is to our staging environment or production) - we do this via cap_gun which integrates with Capistrano.
Notify New Relic RPM of the deploy so it can mark it in our RPM analysis
Notify Hoptoad of the deploy, so it too can have that data when reporting any exceptions
produce our sitemap.xml file, and ping Google to tell them there's a new one
update crontab files (I store our crontab files for each server in our git repo, and then on deploy it sees if there is a new version and updates accordingly, etc.).
flush/restart memcached
There are other ways aside from Capistrano, but it's a proven tool, with a lot of flexibility, yet pretty simple to setup a vanilla configuration.
So, my take is that once you get into any app that is beyond just the very simplest of apps, you're going to need/want to be doing things other than just simply updating the code. In the beginning though, if you just need the code updates, and maybe Rails migrations, then you can do simpler things like Passenger and code sync, or look at tools like Heroku or Engine Yard's stuff where they do a deploy by doing a Git clone (and then offer some additional abilities).
Another super easy way to deploy is with http://heroku.com/
Some of the issues you face with deploying rails to production:
Database connection.
You need to be sure that the database connector is set up for the production environment.
Database migrations.
You have to run database migrations against the production database even though you may have already run them in production/testing/staging
Ruby version. The version or sub-version or Ruby can trip you up, e.g. An error occurred while installing debugger-linecache (1.1.1), and Bundler cannot continue
Gem dependency.
Your production environment may have different packages and gems from development. Bundler will figure this out for the most part and install the dependencies but occasionally there are still issues that you have to resolve manually.
Dependencies.
Some gems on some machine have particular dependencies. I have seen frequent problems with using gems on my unix box that work on OSX and vice-versa.
Note the last 3 shouldn't affect you if on the same machine but I included them based on the title and to be comprehensive.
It's not especially hard. If you stick to conventions then with a little bit of configuration it boils down to this:
cap deploy
...however there is sometimes a bit of effort needed up front to get the workflow in place.
The good news is that lots of people have packaged up solutions and stacks for RoR that you can just plug and play. For example, google ec2onrails - this is a packaged Ubuntu image and set of capistrano tasks for running rails apps in Amazon's EC2 cloud, with lots of common stuff set up already out of the box.
Choose a good hosting provider and you should be able to find something similar for that also.
An easy way to deploy Rails apps is to use Phusion Passenger. Deployment doesn't get much easier than that for any programming language or framework. You can do that on a Mac server.
Another really easy way to deploy rails is with jruby and the glassfish gem.

Limitations in running Ruby/Rails on windows

In the installation documentation to RoR it mentions that there are many limitations to running Ruby on Rails on Windows, and in some cases, whole libraries do not work.
How bad are these limitations, should I always default to Linux to code / run RoR, and is Iron Ruby expected to fix these limitations or are they core to the OS itself?
EDIT Thanks for the answer around installation and running on Linux, but I am really trying to understand the limitations in functionality as referenced in the installation documentation, and non-working libraries - I am trying to find a link to the comment, but it was referenced in an installation read me when I installed the msi package I think
EDIT
Thanks for the references to IronRuby lately, it is certainly a project to watch, and as it, obviously, is a .NET language, it will be invaluable if it lives up to the promises. Eventually, however, in my case, I just bit the bullet and installed an Ubuntu server.
<bias> I should've done it years ago </bias>
Here's an overview of the current issues with Rails on Windows:
Ruby and Rails are slower on Windows than they are on Unix-like OS's.
A few gems and libraries don't work on Windows.
Some Unix-isms aren't available on Windows (examples).
The community is mostly on either Mac or Linux (This is a particularly hard one to deal with; nobody wants to be alone on one island when the rest of the tribe are partying, having fun and getting along great over on the other island. Community is important. It seems that most Windows developers that start with Rails quickly switch to a Mac or Linux. However, the small community of Windows Ruby users that do persist are extremely friendly, dedicated and knowledgeable - go say hi.)
Note much of the advice that follows is now outdated due to the magnificent efforts of the RubyInstaller team in bringing stability, compatibility and performance to Ruby on Windows. I no longer have to use VirtualBox, which says a lot about how far Ruby on Windows has come.
If you want more technical detail, the following are required reading. :
Ruby for Windows - Part 1
Is Windows a supported platform for Ruby? I guess not
Testing the new One-Click Ruby Installer for Windows
Still playing with Ruby on Windows
Chatting with Luis Lavena (Ruby on Windows)
Choice quote from that last one is:
AkitaOnRails: The most obvious thing is that any Gem with C Extensions without proper binaries for Windows will fail. Trying to execute shell commands will fail and RubyInline as well. What else?
Luis Lavena: Hehe, that's just the tip of the iceberg
Having said all that, I don't find developing with Rails on Windows too painful. Using Ruby is, for the most part, a pleasure. I'd avoid InstantRails because, to be frank, it's just as easy to install Ruby properly using the one-click installer, then doing a gem install rails. If you need Apache and MySQL, WAMP is a good bet, although even these aren't required if you just stick with Mongrel and SQLite.
What I've taken to doing recently is running VirtualBox with an instance of Ubuntu Server that closely mirrors the deployment server. I map a network drive to the Ubuntu Server, then I edit and run my code directly on the VM. It uses hardly any memory (it's currently using ~43MB; contrast that with Firefox, which is using ~230MB) and Rails actually performs better than running it natively on Windows. Plus you can experiment with your virtual server in relative safety. It's a really nice setup, I highly recommend it.
Finally, here are a couple of Ruby/Rails blogs aimed at Windows users:
DEV_MEM.dump_to(:blog) (Luis Lavena)
Softies on Rails
Ruby On Windows
I found getting a development environment up and running with Instant Rails on Windows was really simple. Especially when using Netbeans or Radrails as the IDE.
Less than a 10 minute job.
What did those who struggled find to be the problem?
I've been developing Rails on a Windows PC for a couple of years and had no real problems installing back when I first started. However I recently re-built my machine and struggled to get the One-Click Ruby installer working and the latest version of Gems. So this is what I tried.
Option 1: Run a Linux Virtual Machine
I was really impressed with Charles Roper's idea of running Rails within a Linux virtual machine, and this is the route I intially went for. It all went pretty smoothly and I've been documenting it at budanters.blogspot.com. However I've been struggling with accessing the MySQL server (in Linux Virtual Machine) from the Windows host.
Option 2: Use jRuby
I recently installed the Windows version of NetBeans 6.5 Ruby bundle, and without being aware of it, this installs JRuby and the Rails gems. The IDE has a UI to install Gems, and I've now got my old application back up and running in my development enviromnent.
Update November 2009
I now use Netbeans 6.7 on Windows and in the whole I am very happy with it. The only downsides are that it installs JRuby 1.2, and I needed to install JRuby 1.3 manually to get something working (I can't remember what) and I have been completely unable to get deployment working with either Capistrano or Vlad the Deployer to work. Vlad uses Open4 which doesn't work with JRuby.
Update May 2010
Netbeans 6.8 comes with JRuby 1.4 so no longer have to fiddle around with manually installing JRuby 1.3. Also it seems that in JRuby 1.5 Open4 will now work, which means Vlad might start working.
Nobody mentioned Bitnami RubyStack yet? I've been using it for years, together with RadRails. Includes Apache, MySQL/Postgre, phpmyadmin, git etc. Optional Ruby 1.9.2/Rails 3.0b. You may also run the Ubuntu flavor of RubyStack in a VM but I haven't tried that yet.
There is a packaged installer available at http://railsinstaller.org/ which is worth checking out.
Personally I found getting Ruby + Rails up and running on windows a piece of cake. From download to browsing to my first 'HelloWorld' app took me all of 15 minutes. I didn't even bother with any of the InstantRails stuff.
Subsequently I can't say I encountered any of the reported speed problems or issues with Gems under Windows.
These guys also do a nice Ruby developers add on for Visual Studio:
http://www.sapphiresteel.com/
When I last fiddled around with Rails on windows, I used Instant Rails and found it to be a fairly painful process, except for the lack of updates to Instant Rails (which, from the look of the website is still a little bit of a problem, as instant Rails 2.0 uses ROR 2.0, while the newest version is 2.1). You might also look into the answers to this question as it mentions a number of other ways to get RoR running on windows easily.
You have windows options for getting everything up and installed, such as Instantrails:
However, my personal experience with trying to get colleagues up and running on windows is that it's a pretty painful experience. You should be able to get most (if not everything) running, but be prepared to spend a bit of time mucking round (and getting frustrated).
YMMV
I would probably recommend either Linux or Mac for rails development (but I'm slightly biased against windows, so you may need to take that with a grain of salt).
An option if you're stuck on Windows is to have virtual servers running Linux / BSD / what-have-you.
It solves lots of other problems also (allowing you to try multiple server configurations easily, etc.).
If you can't get away from windows use VMware and run some form of linux (ubuntu is popular). Your No.1 limitation will be compiled gems which do not play nicely on windows.
The majority of tutorials assume you're on some form of *nix, it's when you start to break outside of basic scaffolding when you'll feel the pain. Image manipulation, full-text search and even some db adapters will either only run on *nix or are a pain to setup.
The majority of web hosts run linux too, it's good to be developing on the same platform as your host, to avoid deployment headaches.
In general, Rails performance is a problem on Windows.
As far as your deployment setup, you can either run Rails in FCGI or use mongrel (and set up either Apache or IIS as a proxy). mod_rails (http://www.modrails.com) is the best deployment option for Rails today, but doesn't run on Windows.
You might find more luck using JRuby on Windows to run Rails in whatever JVM environment you want (tomcat, J2EE server, etc).
IronRuby isn't there yet to run Rails in a production environment, but eventually it will be aimed at running Rails inside any ASP.NET environment (IIS).
You could just use Cygwin and it's version of Ruby. That gets rid of the arguments about compiled gems not working on Windows - I've managed to compile a lot of gems that way.
The biggest limitation of running under Windows is that a lot of things are super slow.
See this thread. For a discussion.
Simple things like "script/console" and running rake tasks will take 5 times longer on Windows than they do on Linux or Mac.
Other limitations are:
No IE6 on Vista.
BackgroundRB and a many other c based gems do not work on Windows.
No passenger
I'm not a rails developer myself but I thought this may be of interest. Microsoft has released IronRuby 1.0, it's a version of Ruby that runs on the .NET platform that apparently runs 4x faster than the official Rails implementation on Windows.
http://www.drdobbs.com/open-source/224600662
Official site
http://ironruby.codeplex.com/
For a speedup you could try my loader speeder upper (helps rails run faster in doze): https://github.com/rdp/faster_require
Also checkout spork, which works in doze
Alternative of RailsIntaller is RailsFTW. The Ruby & Rails are more updated.

Resources