changing to a new computer - ruby-on-rails

OK, so I have been working through the ruby on rails tutorial by Hartl. I've begun the demo_app. I want to change computers. I downloaded ruby and ruby on rails to my new windows 8 machine. I then copied the folder with all my ruby on rails apps from my old computer to my new one. I thought everything would just work. But, no! I had to run bundle install before I could even start the rails server from within the sample_app. After that things seem to work. But I don't know why I had to do that. Can anyone explain?
Now, I'm not sure what will happen if I install github and heroku on the new machine. I think I already have a new ssh key for one thing. And so I have no idea if I do download both of those if I just continue with my development of the demo_app or if everything is going to be screwed up. Any advice would be appreciated. Yes, I'll read the git book, but I was hoping I could get going with my rails stuff in the meantime if there is some easy way to make the transition to the new machine. Or should I just stick to the old machine until I've learned a lot more about git?

Gems are installed in your default system location for gems, not in your projects. You have copied your project folder but not the gems, that is why you have to bundle install again.

What bundle install does is it installs the required gems by your application to your computer. So naturally if you change the machine, gems that installed to your previous computer is not there in your new machine. That is why you have to run bundle install again.
if you want to install your gems inside the project directory (so that if you change the machines it will not effect you) do the following
bundle install
check this out for more info
HTH

After installing Rails you're halfway there.
Like the other answers say you need a bundle install.
The next step (I would suggest) is the database-server. But you said your app is already working (?). At this point you should be able starting your web using a server like Webrick.
I think the easies way to set up Git, is installing git, set it up (like email and name and this stuff) and then cloning the repository to your new pc (with git clone ...). Of course you can add your new Ssh-key to Github, to have easier accces to GitHub.
I can't tell you so much about heroku because I've never used it. But if you've set up your deployment it should work like before, because (I guess) it also gets the code from github.

Related

Can't Load Rails Server Even Could not find pg-0.17.1 in any of the sources

pretty new to all this and ran into a real ditch. I had ruby 2.0.0p353 running with rails 4.1+, everything was setup with homebrew, xcode, git,heroku etc.... I'm on OSX 10.9.4
then came time to try out S3 and install the aws-sdk gem. I was unable to install the nokogiri gem after scouring stackoverflow for days to no avail. I then came across this article online that suggested to update rails and ruby versions. In my attempt to upgrade my ruby version to the latest, I followed the instructions given here as follows:
in terminal and in my app folder:
/usr/local/opt/ruby/bin
export PATH="/usr/local/opt/ruby/bin:$PATH"
source ~/.bash_profile
gem update --system
..I subsequently tried bundle update / installs as well... and receive this error shown on pastebin: http://pastebin.com/Q64j0LwD
Now, things are completely messed up as I am unable to even run a rails server. Getting this error Could not find pg-0.17.1 in any of the sources
I currently have Ruby 2.1.2p95 installed. I don't know what else is installed during this trial and error probably several versions of many things unfortunately. Any advice would be great.
: Could not find pg-0.17.1 in any of the sources
Try postgresapp and use documentation for install and configure postgresql server.
The easiest way to get started with PostgreSQL on the Mac
You're clearly new to rails coding. I made a lot of mistakes when I started. I still make a lot of mistakes, but they're more complex mistakes now, mostly ;)
I'd start by using "RailsInstaller". Excellent way to get all the pieces... except Postgres. As suggested by someone with a name consisting of a lot of non-ASCII characters, PostgresApp is incredibly useful to get a more up to date Postgres without messing with compiling stuff outside the project.
You probably should use "rvm" or "rbenv" to manage your rubies. I've tried both, and I favour rvm. rbenv is recommended, but I spent an awkward half day trying to disentangle the consequence of typing "bundle exec rails new app", before I decided to go back to rvm. rvm works more naturally for me, at the expense of creating gemsets for each project. Which, personally, I like. I want to isolate each thing I add to an OS, so I can work on multiple projects with less contamination, and without having to create a VM for each project.
Contamination is, I think the problem with Nokogiri. Everyone tells you to go install brew or Macports or build it all for yourself from scratch. When you do, you get lots of stuff installed. And that stuff affects the compilation process. I'm about 80% certain that I can't compile Nokogiri with system libraries because other projects have dropped include files that rename iconv_open to libiconv_open - which isn't in the native library. I have Nokogiri compiling now, but only as a result of using GNU iconv, and using the arcane "bundle config" to set up a build time dependency for nokogiri alone to use the /opt/local/include version of iconv. That was time consuming.
So, some advice that I haven't taken for myself yet. Clean out the brew/ports stuff. I suspect that you can run anything you need to, in locally installed project directories, rather than interfering with the OS. Unless you really need something that doesn't ship with a Mac, like an up to date ruby (solved by rbenv/rvm)
Look into Heroku. Low cost way to get started with publishing your small apps.
Make sure you have GitHub and BitBucket accounts. Personally I contribute to projects on GitHub, but my private stuff is on BitBucket - pricing models.
Git looks mad. But git is wonderful. Learn to branch. Lots. Learn to merge. Learn to tag, and learn how to push and pull from an upstream repo. These words may mean nothing to you now, but they will save your sanity. You'll use git to push your projects to Heroku. Just freaking amazing. Learn how to have a staging branch and a live branch, and push each to a different Heroku instance, so you can be testing user acceptance on a public facing server, without contaminating dev or live versions. Git/Heroku. Joyful.
Watch out for several things that bit me... Ruby gets lots of patches. They are meaningful. I spent days trying to work out why a piece of ruby code failed, only to discover it worked in a different patch level. Watch for the updates and apply them - except for 'bundle update'. Don't do 'bundle update' until you are old and wise.
Gem versions - that also bit me. Got a project that worked. Then it didn't, with no code changes at all... except that I'd updated my gems. A later version of a gem upset the code. So...
Bundler is your other friend. Lock down the versions of gems that you need for a project. Don't use "bundle update" unless you are prepared for strange things to happen. Make nice Gemfiles.
You probably need to get to grips with TDD and preferably BDD.
So next thing you need is to get the Qt library installed, and use "gem 'capybara-webkit'" and Cucumber with Rspec-Rails to help you write tests that the browser will execute. Butt saver central, if you start changing gem versions. At least you know when the tests stopped working, and can use git to revert to a known working chunk. More importantly, it saves, eventually, a lot of tedious checking around when something unexpectedly stops working.
Also... make sure that your development group of gems (in Gemfile) includes "better_errors" and "binding_of_caller". A REPL in the browser pane when your code fails, is wonderful.
If you want to just throw some stuff together, e.g. office admin projects that you don't want to spend a load of time refining the UI on, but just build something that works. Try 'hobo'. I find it very useful for rapidly building something. Faster to code it than to spec it or draw it. Seriously. And it is all over-rideable, though I've never turned any Hobo code into something for high scaled usage...
Welcome to the amazing world of developing in Rails, on a Mac. It's a rapidly evolving hoot. Hope that helps. :)

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

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 :(

What is your version control and deployment workflow with Rails?

Especially when considering a fresh Rails project, what does your version control and deployment workflow look like? What tools do you use?
I'm interested in answers for Mac, *nix and Windows work machines. Assume a *nix server.
I'll edit for clarity if need be.
Create a copy of my personal Rails 2.1.1 template with preinstalled plugins and frozen gems.
Change DB passwords, session secret/name and deploy.rb.
Create a private or public repository on GitHub as needed.
Push the empty rails project to GitHub.
SSH to Server and configure apache (copy Virtual Host file and mongrel config files from old project)
Create empty database on MySQL server
cap deploy:setup && cap deploy:cold
If everything works so far: Start developing and committing to GitHub. cap deploy as needed.
Update: Don't forget to write tests for everything you do!
Using Windows Vista and a fresh Ubuntu install at Slicehost.
Create a new empty project in
NetBeans.
Fire deprec (http://www.deprec.org) to install
the Rails stack, including version
control, on the target slice.
Commit the empty project to Subversion.
Using Capistrano, test deploy.
Begin actual development after I've verified that I can access the
Rails start page and, possibly,
scaffolding. (This is really not
necessary because I've done this several times and the software works like it says it does.)
Deprec is seriously magic -- it takes the time it takes to clean-start a Rails project (including server configuration and all that jazz) from about a working day down to about an hour -- and that is an hour where you can be doing coding while everything installs.
this guy documents every workflow he's ever experienced
http://subtlegradient.com/articles/2007/03/30/web-development-environment-and-workflow

Resources