Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between: rails vs. bin/rails?

as freshman, I come across many unclear details. One of those is bin-thing. I've been wondering what's the difference between:

rails generate... 

and

bin/rails generate...

? They seem to behave the same when I run those commands in console. There is also rake and bin/rake... and many more probably. Thanks for help.

-- greetings

like image 720
zombie_ghast Avatar asked Aug 15 '14 21:08

zombie_ghast


People also ask

What is difference between bin Rails and Rails?

If you have a project which uses an older version of Rails and you run 'rails', you can run into problems when trying to run code that's changed in the latest Rails version. Binstubs fix this problem by making sure your environment uses the versions specified in your project's Gemfile.

What is bin in Ruby on Rails?

bin/rails about gives information about version numbers for Ruby, RubyGems, Rails, the Rails subcomponents, your application's folder, the current Rails environment name, your app's database adapter, and schema version.

What is Rails console?

Rails console is a command line program for interacting with the Rails applications. It has the full power of the Ruby language and Rails environment.


2 Answers

If you just run 'rails', RubyGems will activate the latest version of the rails executable it can find in PATH. This is fine as long as you use this version of Rails in your project. If you have a project which uses an older version of Rails and you run 'rails', you can run into problems when trying to run code that's changed in the latest Rails version. Binstubs fix this problem by making sure your environment uses the versions specified in your project's Gemfile.

like image 139
Ahmed Ali Avatar answered Oct 12 '22 10:10

Ahmed Ali


Consider this scenario:

I had an app that was using Rails version 4.0.0. My goal was to upgrade it to Rails 4.1.9. To do so, I tried to upgrade it step by step: first, upgrading to 4.0.13, then 4.1 and finally 4.1.9.

Everything went smoothly. All the tests were passing using RSpec.

Finally, I tried to run my server with rails s. Booom! Ruby crashed. Then, I used bin/rails s. Everything went ok.

So I think if you have different version of rails set up in your system, it's safer to use bin/rails option.

P.S. To make sure that my assumption is correct, I removed all rails version except 4.1.9 and then I tried to rerun the server with rails s. No crash this time.

Hope this clarifies.

like image 23
Dave Qorashi Avatar answered Oct 12 '22 11:10

Dave Qorashi