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

as a freshman, I come across many obscure details. One of them is bin -thing. I was wondering what the difference is between:

rails generate... 

and

 bin/rails generate... 

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

- greetings

+6
source share
2 answers

If you just run rails, RubyGems activates the latest rails executable, which it can find in PATH. This is great if you use this version of Rails in your project. If you have a project that uses the old version of Rails and you run rails, you may run into problems trying to run code that was changed in the latest version of Rails. Binstubs fix this problem by making sure your environment uses the versions specified in your Gemfile project.

+3
source

Consider this scenario:

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

Everything went smoothly. All tests passed using RSpec.

Finally, I tried to start my server using rails s . Booom! Rubin crashed. Then I used bin/rails s . Everything went fine.

Therefore, I think that if you have a different version of the rails configured on your system, it is safer to use the bin/rails option.

PS To make sure my assumption is correct, I uninstalled the entire rails version except 4.1.9, and then tried to restart the server using rails s . There are no glitches this time.

Hope this clarifies.

0
source

Source: https://habr.com/ru/post/973878/


All Articles