copies a rails app to a new computer: rails command not found - ruby-on-rails

I have just set up ruby and rails on a freshly installed freeBSD. It works great. I can do rails new blabla mv into blabla and do rails s and it just works.
I had an up and running rails app on another computer. I copied the repertory that contained the app to the new computer running freeBSD. However, when I mv into that repertory of the rails app and to rails server I get -bash: rails: command not found
I have tried creating a new app with the same name and let rails create all the repertories and then copy the files of the existing rails app therein but no success.
I can run rails -v and rails s from within any repertory and get correct answer, but when I move into that specific repertory I get that command not found.

You're probably using a ruby version manager I suspect (rbenv/rvm)? Check the ruby version in your Gemfile (top of the file). It probably isn't the same as the ruby version you have installed. If you're using one of the above mentioned version managers than install the correct ruby for your rails project. After that you can do a gem install bundler in the project directory and after run bundle install which will install rails and all dependencies.

Which version you are using? It happens with earlier versions. Try updating your gems and bundler. And try again. Hope it helps.

Did you try running bin/rails s? I think tha you need run bundle install too.

Related

Adding ruby on rails to an existing react native app

Background
I'm developing a React Native app for the first time. I've gotten to the point where I need to start working on the back end and I'm going to use Ruby on Rails to do that. I've installed Ruby and SQLite3, and I've successfully added Ruby to my project.
Problem
As of right now, when I try to install bcrypt and jwt to the Gemfile in the project, I ran gem install bcrypt/jwt and that seemed to work, but when I try to run bundle i get an error: "Could not locate Gemfile". I am certain the Gemfile is in the directory I'm running the commands in, as I can see it in VS Code and also going down the path in C:/, etc.
Question
Can I actually add Ruby on Rails to an existing project? What could be the cause of this issue?
Thanks a lot!
If you have created a new Rails-App via rails new myapp you can cd into this directory and call bundle install.
rails new myApp && cd myApp && bund
Please check that you are in the correct directory. If you are sure that you are in the right directory then check your current rails version with rails --version.
Make sure you are in the project directory before running bundle install. For example, after running rails new myproject, you will want to cd myproject before running bundle install.
gem install - like npm install -g, programm to fetch gems,
bundle is fetching list of gems from Gemfile in your app(current folder), like package.json (not sure about naming)
1. Can I actually add Ruby on Rails to an existing project?
Yes, sure. You have a lot of variation to do that
here link the good article how create rails-react app, then you can move your front end part to react folder in the new rails application.
you can create new rails as separated application, in folder what you want as API with option rails new your_app_name --api, then send requests from react app directly to rails app port or IP(it is harder to implement, but I think it is right solution).
2. What could be the cause of this issue?
it is possible because you do not have rails app do not exist
you do not have Gemfile in your folder.

how do i fix the error message i received when running bundle install?

I am new to ruby and rails. I just installed Xcode, homebrew, rvm, a new version of ruby, and a new version of rails. I started a dummy project. I ran rails new MySite and bundle install. When I ran bundle install I got the following error:
Could not locate Gemfile or .bundle/ directory.
Did I do something wrong on the installation? How do I fix it? I have not tried anything to fix the problem because I do not know where to start.
Rails will run bundle install by default when you create using rails new MySite.
In any case the reason why it did not work is most likely because you weren't in the directory containing the Gemfile, just cd MySite and then run bundle install
First use the command:
bundle init
This will set up a new ./Gemfile in the current directory.
documentation: http://bundler.io/v1.12/bundle_init.html
code: https://github.com/bundler/bundler/blob/dfdeb0f89e7e88fcdfd001da089f09af3a77d2b4/lib/bundler/cli/init.rb
Also see this guide about using Bundler with Rails: http://bundler.io/rails3.html. The guide is for Rails 3, but it should work for Rails 4 too.

Do I have to install Rails on every new project?

This is a beginner-level question.
I'm using Ubuntu 12.04
I copied a project (created on Rails 4 using the rails new command) from Dropbox to my local environment, where I have previously install Rails 4 and up-to-date Ruby and RVM, went to project's directory, typed rails server and got
The program 'rails' is currently not installed. You can install it by typing:
sudo apt-get install rails
I ran gem install rails instead.
Will I have to run gem install rails on every project's directory? I thought the Rails install was a general and accessible on my whole environment.
The project was created using the same Ruby version, but on a MacOS X system.
The project is a static web brochure and has no database configuration.
Thank you in advance.
Make sure you're using the correct version of Ruby - the same version that you'd installed Rails into - with rvm list.
You likely have two of them (since you have such an issue) - the system Ruby and the RVM-installed Ruby. And likely RVM didn't engage and hook up the correct path to the rails executable, thus the error.
This should fix the issue:
rvm use whatever-ruby-you-had-installed-rails-into
Where whatever-ruby-you-had-installed-rails-into is a string like ruby-2.1.0-p0 taken from the rvm list output.
To make RVM retain Ruby version for the project.
echo whatever-ruby-you-had-installed-into >.ruby-version
in your project's path.
So after a few hours of testing, reproducing the problem, and reading (the other answers inclusive) I got the solution as follows:
Short answer: No. Rails needs to be installed only once.
Long answer: This problem occurred because of a default setting on Terminal that prevents the system from using RVM installations of ruby and rails. The solution is to integrate RVM with gnome-terminal as described in the RVM website.
With terminal window active, go to the menu at the top bar
Edit > Profile Preferences > Title and Command tab
Check the Run command as a login shell box
Restart Terminal and make sure your gemset and ruby version are set
rails server should now work as expected (you might be prompted to run bundle install before Rails can actually run fine, follow the promtp).
I am still learning to work with Ruby on Rails, so any inputs, clarifications, or additional information on the issue is more than welcome.
You don't have to install Rails on every project, but the gems that you need for that project.
With bundle install you install all the gems that you specify in Gemfile.
If you want to avoid reinstall the gems every time you change project, I suggest you to have a better look to RVM: it has got an opt called gemset (https://rvm.io/gemsets), if you use it you just need to switch your gemset:
rvm gemset use yourgemset
I hope it can help you.

Rails not working on Mac in new terminal window

I have been using RVM (Rails 2.0.0) for a project in the terminal doing commands etc. and have noticed that when I opened a new terminal page the rails command didn't work it just shot back the error:
Rails is not currently installed on this system. To get the latest version, simply type:
$ sudo gem install rails
But I had it installed and have even built half an app using it so far... what happened all of a sudden and how do I fix it to keep going with my project.
I was having the same problem on with the Rails tutorial. It looks like rvm is using the gemset defined in the Gemfile to override the default gemset. You should see this if you execute:
rvm gemset list_all
What I saw was this:
(default)
global
=> railstutorial_rails_4_0
So rails is fully installed in rvm's default gemset, but not in the new one ("railstutorial_rails_4_0" in this case). I solved this with the following commands:
bundle install --without production
bundle update
bundle install
This solution appears to have persisted across terminal sessions.
Okay so I got it to work by simple removing the code in the Gemfile that states the version of Ruby the app is to use and then it worked fine. Must of been some conflict with RVM installed on my machine and the Gemfile.

Rails not found after Mac Update

I just ran an Update on my Snow Leopard and today when I tried to run Rails server I got the following:
Rails is not currently installed on this system. To get the latest
version, simply type:
$ sudo gem install rails
On Echo $PATH I get following:
/opt/local/bin:/opt/local/sbin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/local/git/bin:/usr/X11/bin
Update
Running the command giving above for installing rails did not do any harm. I guess updating process removed previous links of rails. the latest version of Rails and dependencies got installed and things working perfect
Try this command
which rails
and see if rails is installed. If it is, add it to your executable path

Resources