How to import existing ROR project? - ruby-on-rails

I'm new to Ruby on Rails (PHP developer here) and I need to edit an existing ROR project. I've been using Aptana Studio for my PHP projects (switched to Zend after Aptana 2.0) but I've kept Aptana RadRails for my ruby projects.
So what I want to do is to get the ROR project from the server (it's hosted on some linux machine) and import it into RadRails for local development. I've downloaded the files from the server and imported them in a new RadRails ROR project but it doesn't work as intended. Is there anything else I should do ? I've read about 'freezing the gems', switching to production mode and dumping the database for a ROR project upon releasing. Are there some steps needed to undo those operations ?
UPDATE:
The problem that I'm having is that I get various errors when trying to visualize in the browser the pages for different controllers.
ActionController::InvalidAuthenticityToken in
No :secret given to the #protect_from_forgery call. Set that or use a session store capable of generating its own keys (Cookie Session Store).
OR
no such file to load -- xml
This error occurred while loading the following files:
hotels_pro
xml
This leads me to believe that (maybe) I haven't got all the files. On the other hand I have double-checked and I have all the files from the server.
Thanks,

A RoR application is more than just the sum of its source files. There's also the database, gems and a server which exist outside the project directory. Without knowing exactly what doesn't we can only speculate which is causing you problems. Being new to Rails, it's probably all of them. If after all this you're still not up and running a few rounds of "Google the Error" should fix you up.
You'll need to set these things up in your development environment before you can proceed. The following assumes you have a working ruby environment: rubygems installed with the rails, and rake gems. Note any commands and paths that follow are relative to the root of your rails project.
Database:
Start with editing config/databases.yml to find out which database your app will try to connect to. Change it if necessary so it names a local database. Create that database, if it doesn't exist with $rake db:create
If you need existing data to test with you can take a dump from your production database and import it into your working database. How to do this is dependent on the type of database in question. Otherwise you can run the migrations with $ rake db:migrate to produce your development database (assuming the previous developer designed the database with migrations.)
Gems:
Check the config/environment.rb, for your list of required gems. Install all these gems if they haven't been already.
If you're using Rails 2.1 or newer, you can streamline this process by ensuring that all gems are required using the newer config.gem 'this_gem' form instead of older require 'this_gem' declaration. Once all required gems are in this form, you can use $ rake gems:install && rake gems:build to ensure they're all installed.
Server:
Is pretty trivial, all rails instalations come with web brick which is fine for development. But mongrel is also suitable.
P.S. If you're not using some kind of revision control it's strongly advised to set something up before starting. It's not a requirement, but it will likely save your ass at some point.

Related

I have a complete ruby project on my system but how do I run it?

I have a complete ruby project on my system that I downloaded from github.com and I want to run it on my Windows machine.
I have already installed Ruby and Rails on my system, but I have no idea how to run this project. The directory of this project is something like:
C:\Users\{username}\Desktop\BitcoinFundi\BitcoinFundi
How would I run this project on my system?
To run your Ruby on Rails application, use the following command:
rails server
This will start the server and you will be able to access the application in your browser at http://localhost:3000. Port 3000 is default and you can change it in the application settings.
To run a Ruby script use:
ruby name_of_script.rb
You should check out various resources and tutorials on getting started with rails.
As you say in your comment this is your first experience with Ruby on Rails, I think you should follow through chapter 1 and 2 (at least) of Ruby on Rails Tutorial. After that you should have a better understanding of how you start up a rails app and configure the DB. You also need a bunch of other libraries and software such as mysql from the sounds of it.
You should also read Getting Started with Rails. Section 4 covers how to start the default rails server.
Here is a guide on setting up a Rails environment for Windows, which is one of many guides, that shows you some of the needed steps to get a fully working environment.

How do I set up an old Ruby on Rails project on a new server?

I'm not a RoR programmer myself, but a good client of ours has sent a project their previous web team built and I need to get it up and running on their server.
The server uses cPanel and Ruby on Rails is already installed. I've created a project via the cPanel wizard and located the file tree via SSH.
Using SSH, I've tried to replace this file tree with the project I've been sent, but when I hit 'run' in cPanel, the application doesn't actually start (although the success message would indicate that it has).
If I leave the original cPanel-created application in place, I can run/stop no problem and the web interface at :12001 opens up just fine.
I assume there are either conflicts with RoR versions that I need to resolve, or there's simply more to it than just replacing the file tree? Again I'm not a RoR programmer and I'm having a hard time finding a migration guide that tells me anything other than "set up in cPanel and replace the files".
I'd very much appreciate either some genuinely useful links to RoR application setup/migration guides (ideally for cPanel) or a step-by-step answer please.
First, forget Cpanel for now. Try in one environment where you can control everything.
Try to know better the rails version used and the associated gem19s or plugin if from 2.x days. The ruby version is important too, only then you can start defining a plan.
I'm afraid you won't get a step-by-step answer, but I'm sure you can be pointed in the right direction by providing the requested information.
Simple questions: Do you have a Gemfile file at the top at your project? Do you have any plugins (stuff in vendor/plugins)?
Update:
With the Gemfile provided here are the required steps:
Install ruby (if you haven't install it using rvm. The version 1.9.3-x should be the safest.
Install rubygems
Install bundler
Go the project dir and run bundle install
run rake db:migrate (assure you have the database setup acording to config/database.yml
run rails s and check the logs and see if the server is up.
If after installing bundler, you don't have the bundle command in your path, you need to add this your .bash_profile:
PATH=$PATH:$HOME/.local/bin:$HOME/bin
export PATH

Grab Ruby on Rails files and install on local machine

general question that can be used in many different situations, so I thought it would be interesting to ask.
I'm semi new to Ruby and am learning from Treehouse. I am doing the social media site project, and am about half way through.
I was hoping to set up a separate installation from the source files they give you, of the completed site, to do a simple compare and contrast, and really I am just curious as to what the final product is gonna be like.
My question is, is there an easy way to just grab their files, install all the gems and dependencies and run the rails server. If I just try to run the server on the folder, I get a bunch of errors about Gems not being installed and such, which is expected.
If anyone has a process they use when doing things like migrated entire environments from one location to another, it would be appreciated!
Go to project directory.
Install all of the required Gems by executing
bundle install
Create database by executing
rake db:create
Then migrate the database by executing
rake db:migrate
And finally run the application using
rails s
If you have cloned their repository, or copied the files to a folder, try running
bundle install
from the command line

Rails 3.1 application deployment tutorial

I'm looking for a good deployment tutorial for a Rails 3.1.1 application on a server. And by good I actually mean complete. The reason I'm posting this question is that although there are tons of tutorials out there on the web (google, blogs, books, other stackoverflow questions etc...) all of them seem to focus either on a problem with the deployment process or make some assumptions about the deployment environment that do not match with what I need.
I realize that deploying a Rails app on a server requieres a variety of different programs and tools that need to be configured and somehow I always get stuck on apparently "little" things that make me very frustrated.
So, let's begin from the start. What I have now is a server that I can access through SSH and a domain name, let's call it www.example.com. The server runs a fresh Ubuntu 10.04 x64 and has just a user installed, namely root (through root I access the server with SSH).
Note! There is no Apache, Ruby, PHP, MySQL, cPanel or any other panel installed, just the bare minimum that comes with a fresh installation.
Also the web server will host a single application and the database will run on the same machine.
From my knowledge the process of deploying a Rails application follows the following scenarios:
Installing Ruby
I already did this by using RVM using the Multi-User install process (simply because I have just the root user and it does it automatically). This seems to work fine aftewards but I do have some questions:
Would it make more sense to install Ruby directly and not through RVM (I'm thinking maybe in terms of efficiency - also RVM does a little bit of magic behind the scences modifying some bash_profile files in ways that I don't understand and this somehow seems invasive...)?
Would it make more sense to install as a separate user through RVM (can there any safety problems arise)?
Necessary gems
Now that Ruby is installed what would be the best initial set of gems to install along side it?
I installed just bundler, so that once I upload my application on the server I can run a bundle install command which will install in turn the required app gems.
Question - Should I install the rails gem before hand? Are there any other gems that need to be installed?
Web server
This is where it gets tricky for me. I'm trying to use apache and mod-passenger for deployment (they seem to be the most popular). So I installed the apache web server and the passenger gem and all the related dependencies (libraries mentioned by passenger).
Now, the problems arise. First thing is user related. How does Apache run? I mean under each user? If I installed it and (re)started it using the root user, will it permanently run under the root user? Is this a bad thing? If yes, should I create another user? If yes, how? In what groups should I put the new user in, what rights should he have (namely what folders should he have access to). How to start the apache in this case (under root, under that user, add a line somewhere in the configuration file, etc.)
Website configuration
Where to put the website configuration stuff? Is it OK to put it into apache.conf, or should I create a new file in sites-available? Or should I simply reuse the default file that is already present there? If a new user has been created at the previous step, what rights should he have in relation to the config files?
Also... where to eventually put the rails application? In what folder would it be best? Somewhere under home? Maybe under /var/www? I want to know how would this affect the rights of the apache process serving the app? (Generally I have problems while serving an app, it complains that it doesn't have rights on a specific folder. Also, using the new asset pipelines - which I don't fully understand - asset files are being created and they seem not to inherit the parent folder rights...)
Database
As database I'm using MySQL and installing it is pretty straightforward. The question that I have here is again user related. Should I use a special user for the database? How does MySQL actually manage users (are they internal, or are they the Linux users or ...?). Should the database user be the same as the "web user" from above? Or should it be a different one?
Assets
Here I get really lost. I really have troubles making the assets pipeline works. I've checked the railscasts episode and also the rails website tutorial and I do seem to theoretically understand the thing, yet I have problems in practice.
So the questions here would be - what commands should I run to precompile the assets? (Trying to run rake assets:precompile). Is it ok? What should I change in the production.rb file? How do the assets generated work in relation with the webuser or database users created above? I am personally getting a problem in this step namely the log files say that some css files are not accessible (for example I have jqplot library installed under the vendor/assets folder and its files cannot be accessed - should I add a manifest file here somehow?).
It would be really great if someone could point me towards a nice article, or resource that explains all this stuff. The main area which I'm having problems in is how does Apache, Passenger, Ruby, Rails and MySQL interact with a Linux user. How to properly set up the permissions for the Rails app folder? How does the assets pipeline affect this user permission stuff?
Thank you
Here's my way of deploying Rails:
Installing Ruby
I would not use RVM because it's very tricky to get it running properly in combination with stuff like cron jobs. Doable (with wrappers for example), but a bit of a hassle. If you don't need other Ruby versions on that machine, just install it from source yourself.
Gems
Just let Bundler work its magic. Remember to install with the flags --without test development --deployment. I wouldn't do that up front though. Just make sure you have bundler.
Web server
Using Passenger (with either Apache or Nginx) is a fine and easy choice. When you install Apache from apt, it will run in a special user.
Apache is configured correctly automatically on Ubuntu. It will start on reboot.
Website configuration
All configuration be in /etc/apache2. Place your virtual host configuration in /etc/apache2/sites-available and use a2ensite to enable it.
Put your app in /var/www, since that is the default location in Ubuntu. I usually make a deploy user.
Make sure that user can access your application by assigning your app to the www-data group.
Database
MySQL has its own user system. Log in as root user and create a new user with SQL: GRANT ALL ON 'application_production'.* TO 'deploy' IDENTIFIED BY 'some password';
Assets
Assets should be generated as the user owning the application. You should add any css and javascript files to production.rb. For example:
config.assets.precompile += %w(backend.css)
Conclusion
It helps to use a deploy tool like Capistrano. When you run capify, uncomment the appropriate line in the Capfile to get assets compilation. Here's mine:
ENV['RAILS_ENV'] = 'production'
load 'deploy' if respond_to?(:namespace) # cap2 differentiator
load 'deploy/assets'
load 'config/deploy'
require 'capistrano/ext/multistage'
require "bundler/capistrano"
require 'capistrano_colors'
This is just how I normally install my rails apps. I hope this will get you going. Recently I've written a gem for integrating Chef-solo with Capistrano, called capistrano-chef-solo. It's very alpha and might be a bit too complicated if you're just starting with deployment, but it might help you.

Railties in Rails 2.3 project?

I've inherited a small Rails project from a new client and unfortunately the previous developer(s) left essentially no information other than the Rails app instance running in production. (No source repository, no documentation, just the login to the production server.)
Inspecting the server shows Rails version 2.3.8 installed (confirmed by the version number in "config/environment.rb") but when I try to run "ruby script/console" (or "server") on my local dev environment I get (essentially fatal) error messages originating from files in "vendor/rails/railties" and searching the internet for "railties" shows a lot of Rails 3 documentation.
I'm guessing that a previous developer/maintainer crossed the Rails 2/3 streams somehow. Should I be ok to just delete the entire "vendor/rails" directory or am I missing something?
What kind of error are you getting? Do you know that your local environment is the same as production? Do other Rails 2.3.8 projects run fine on your machine?
Now, I think it should be fine to remove vendor/rails with the exception being that if the previous developer monkeypatched something in Rails, but directly in the vendor/rails directory. Then, you might have a problem.
This approach might be a bit tedious, but I might go as follows:
Clone 2.3.8 somewhere else on my machine.
Check it in to some form of version control.
Copy your version of 2.3.8 from the project into the newly cloned directory.
Diff it.
This should show you if the previous developer made any changes, both significant and insignificant, to Rails.
Good luck, because this doesn't sound very fun :(

Resources