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
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.
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.
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With