How to preview rails? - ruby-on-rails

A website is shared to me on github. I'm working on it, but I can't do modifications on the actual site page yet. I need to see how the changes I make look like.
How can I have a live preview from rails? I was used to use xampp for the html/css stuff. Is there anything similar to that? If not, what are my choices?

The usual workflow is to setup a development environment on your local machine. The tools you will need for this are roughly:
git, to clone the github repository to your local machine
ruby (what version you need depends on the project), preferably you use a version manager such as rvm or rbenv
the correct database (again depending on your project, e.g. mysql or postgresql)
Once you have a ruby version installed, the first step will be to run 'bundle' to install all dependent ruby libraries. If that was successful you can configure your database in a file that either exists already or should be added: config/database.yml in which you configure the database connection.
You would use the command 'rake db:create db:migrate' to setup the database according to the projects migrations (=> specifying the database layout).
You might want to make yourself a bit familiar with ruby on rails, by following some good beginners tutorial. In the official rails guides that would be: http://guides.rubyonrails.org/getting_started.html
It is not as 'out-of-the-box' as you might be used to from xampp , so there might be a bunch of pitfalls in the way (especially if you're running on windows and not linux / mac).
It is hard to give you a complete walkthrough without knowing the application and your system.
Depending on who's developing the application you might also ask them to provide you with a VM, e.g. using a tool called 'vagrant' to simplify the setup for you. You will still need to get more familiar with git, in case you aren't yet.

Hi you can first keep your apache on xampp running normal.
Go to command prompt if you are on windows. Go to the root of your application on your computer.
Then run
rails server
To open the server. If you done all that correctly it should open on your browser at
Localhost:3000
Then you can take it from there.

Related

Ruby on Rails app : from Heroku to a local server : what are the main steps?

My Ruby on Rails app (basically a commenting and voting system) has been deployed and currently runs on Heroku. I need to deploy it on a local server to ensure an optimal performance for a customer-organized event in a location where the internet bandwidth is too low and unpredictable to support the 100+ simultaneous users.
Just as Ruby, Rails, Javascript, JQuery, AJAX and CSSs were new to me a few months ago, going local is something new I need and am eager to learn (which should also allow me to deploy onto a dedicated or virtual private server if needed).
The following elements are obviously on the way : choosing an operating system, installing Ruby on Rails, a web server, a database engine and deploying my app code and data of course but I need help to make sure I do not forget anything and really understand how all of these elements must be tied together to get my app running.
At a reasonably high level, starting with my app code, could you please share your experience and tell me the steps I need to take from scratch to have it run on a local server ?
If you have a Mac, then you're already most of the way there. I do all of my Rails development on OS X. The steps from there are pretty easy.
Install Homebrew. This will help you quickly install any dependencies on the Mac that your Rails app needs (such as a database). Since you're on Heroku, you're likely using Postgres. So with Homebrew, you can install Postgres via brew install postgresql.
Copy your app code somewhere that makes sense. I have all my apps inside my ~/Projects directory.
Recommended: Install RVM. This will help keep gemsets unique to projects and keep your global gemset clean.
If you're using bundler, do bundle install within your app's directory.
Within the app directory, do: rake db:setup (Note: This may require prepending bundle exec)
Start your server. I tend to use Unicorn (see Heroku's deployment with Unicorn for even more details), so this would just be unicorn. Else, rails s works as well.
Those are the high level steps to get a local server running.

deploy a ruby on rails application

I'm trying to deploy a ruby on rails application. It uses mysql for
a database. What I would like to do is distribute it as a windows
executable. It should be in such a way that the user can click on the
application and everything will load and a full screen browser window
will appear. This way the user will know nothing about it being a
browser and need no ruby components installed to run the application.
i am using 3.2.6 , ruby 1.9.3 , gem 1.8.24
Has anyone done anything like this?
Well, you can create a portable distribution - self-extracting archive that will extract your Rails application, pre-configured Ruby package with all necessary gems, and a bat-file, that will add Ruby to PATH variable, run Rails server and open browser window. Making a MySQL portable will definitely be a pain in the ass, I presume.
One of the key disadvantages is almost zero level compatibility - some gems will not work on certain systems, incompatible database drivers etc.
I once tried to do the same thing with Apache+MySQL+PHP, ended up using one shared PC as a server, distributing just browser launcher as a standalone app.
This might be a job for JRuby.
Try installing JRuby on your development machine and seeing whether your app runs in JRuby without any compatibility issues. These days that's reasonably likely.
Running your app in JRuby gives you the ability to package up all of Ruby, Rails, your gems and your application as a single .war file which can then be deployed within a java application server like Tomcat (using tools like warbler)
This still leaves you with the task of installing all the infrastructure (database, java, java application server etc).
I'ld try to prepackage a virtual linux box with all what your application needs and release that instead.
And, yes, I am very interested in the final answer as well :-)

How to deploy Ruby on Rails application via cPanel on shared host?

I am in the process of learning Ruby on Rails and things have been going smoothly - up until I tried to deploy one of my test applications to my shared hosting account.
I use Host Gator and was able to successfully create a new Ruby on Rails app via cPanel and run it. The only problem is that when you create a new app this way, it populates its directory with a blank application - as would rails new app_name locally. When I delete the files and folders in this directory and replace them with my own, then attempt to run the app, cPanel says that it is running on the confirmation page but it never actually starts. I am not receiving any error messages either.
The host seemed rather stumped, stating that it should be a matter of deleting the initial files and folders and replacing them, then running. The app works fine locally so I do not think that it is a code issue. In my research I came across Passenger, although it is way over my head and it would appear that you really need to have total control over Apache to make it all work, including ssh.
If it makes any difference, the apps I made locally were put together using an installation of Rails Installer and are scaffolded. For testing I am using a bare minimum app with about three fields in the table.
What am I missing? Any help would be appreciated.
Maximum supported versions on 26/10/2013 are:
Ruby 1.8.7
RubyGems 1.8.25
Rails 2.3.18
Anything newer than that is a near guaranteed breakage and cPanel & WHM will be incapable of utilizing it in any way, shape, or form.
We can assist you with removing your existing Ruby on Rails installations and reverting them back to cPanel supported and sanctioned versions (Ruby 1.8, RubyGems 1.8, and Rails 2). That is the only thing we can do for you at this time.
If you want to use any versions newer than this, then you will be unable to use the cPanel & WHM interfaces or management tools for it -- they simply will not work. You will then have to manually manage your RoR install by yourself through command line exclusively. None of it would fall under the scope of cPanel support.
You can use http://ndeploy.in which is a third party plugin to integrate Rails Hosting via Phsuion Passenger in cPanel .
Just to let others who is using Cpanel with rails know.
I was able to use Cpanel to create a rails app, start it, and do the redirection all within Cpanel.
Nothing to modify or change. Quite straightforward for me.
So I guess it would be easier to do the development work straight on the server itself.
Have not tried to deploy a locally developed rails to shared server, or any per se. But I'm guessing we could create rails with Cpanel and replace the files in the directory generated.

Is it possible to 'clone' my Rails development machine?

I just began the process of setting up a new Mac as a Rails development machine, but the thought occurred to me: do I have to do all this again from scratch or can I somehow copy/clone my development environment from my existing machine (also a Mac).
Could I, for example, clone my machine using SuperDuper? Or are there any other tools to make the process of developing from more than one machine less agonizing than manually re-installing databases, Ruby, Rails, etc?
Thanks in advance for any ideas.
The rails framework itself is designed to be highly portable, especially version 3 ( with the introduction of a tool called bundler ), it lets you package all of your code and dependencies very easily which makes redeploying elsewhere simple.
Also you could look into using a tool such as RVM for managing ruby installations, RVM makes it very easy to deploy new versions of ruby into any environment.
http://rvm.beginrescueend.com/
And bundler:
http://gembundler.com/
The whole ethos of Ruby and Rails is based around portability and transparency. Once you start developing with it you start to see how easy it is to redeploy your app to other environments.
If you use a distributed version control system like git, you'll be able to pull down a copy of your application to any machine connected to the web.
Capistrano is also something you might want to look at, its a deployment tool and if you couple it with a version control tool such as git, you have a very powerful combination for pushing updates/changes to your deployed application
You can use Carbon Copy Cloner (http://www.bombich.com/) to copy your HD to another, which you can boot from. Also, if you use TimeMachine on another drive/network drive, then you can restore another machine from the backup.

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.

Resources