What is the use of gemfile in rails?

What is the use of Gemfile in rails?

How to use Gemfile ?

+42
ruby ruby-on-rails gemfile
Dec 28
source share
5 answers

During your development in Rails, there will be times when you want to provide some functionality that you need, but either you don’t know how to do this, or you don’t want to implement it yourself, since a lot of work was brought into its development by talented developers.

These developments that you may need (user authentication, message system, resource handlers, geolocation, pagination system, communication with external services such as Amazon AWS and, last but not least Rails) are called Ruby Gems. These are ruby ​​software packages that are not necessarily Rails, but since Rails is based on Ruby, 98% of the gems may be available for your Rails web server code.

A lot of gems can be found on github , but its a gem hunter for searching gems through ruby-gems or ruby-toolbox

Your gemfile is a list of all the gems you want to include in the project. It is used with a bundler (also a gem) for installing, updating, removing and managing other used gems.

gemfile has a different purpose: you can group gems in groups :development gemfile :production , etc., and Rails will know when to include gems. For example:

 group :development, :test do gem "rspec-rails" gem "factory_girl_rails" gem "guard-rspec" end 

Note that in Rails 4, the assets group is deprecated.

These gems belong to the development and test environments, as they are designed to test the application. You do not need them in a production environment (you could, but it inflates memory unnecessarily).

So - To use the gemfile , just write the gem you want to install, for example

 gem 'devise' 

be sure to install bundler in advance (in the console / cmd / ssh) with

 $ gem install bundler 

and then write to the console

 bundle install 

You will notice that another gemfile will appear! Gemfile.lock This file, as you will see, if you open it using text reading, lists all your gems with their version and their dependencies. This is useful when you need to know which versions of the stones you have installed.

Read more on the gemfile page - on the supplier’s page.

for information on choosing a gem, you can start with this

Good luck and have fun!




Ok, so what is the generated Gemfile.lock?

Gemfile.lock, as the name implies, is a lock on all versions of all installed gems. Therefore, if the Gemfile is what is required for installation, the lock file is what is installed and what version is really required to run the application.

If you don’t have gems in this particular version (as indicated in Gemfile.lock), the rails will complain and you will either have to install the missing gems (via bundle install ) or fix any conflicts manually (I believe the link will give you some hints)

Some Things You Need to Know About Gemfile.lock

  • If you accidentally delete it, it will be restored when you run bundle install . If you accidentally delete gemfile , you're out of luck. You must use git :)
  • Heroku does not care about Gemfile.lock as it reinstalls all the gems. So, for Heroku you have to install the gem version you want, or Heroku will always install the latest gem, which can cause problems.
  • Keep the Gemfile.lock file in your project so you always know which version of the gemstone makes your application work.
+80
Dec 28 '12 at 17:45
source share

Gemfile are a configuration for the bundler that is used to manage your Ruby application dependencies. This website contains a lot of documentation, including the Gemfile man page .

+10
Dec 28 '12 at 17:05
source share

I will try to give a simple answer

Similar explanation

Suppose you want to make a car. From scratch. Now it will be a nightmare. You need to build: chassis, engine, escort, radiator, cooling, ventilation, etc. Etc. Etc.

Gemstones allow you to use auto parts that other people have done before

But you are not the only one who built the car. Everyone who ever built a car basically did the same. There were smart people who went there and made internal combustion engines, etc. Long before you ........... it really doesn't matter.

You do not need to reinvent the wheel. Why create your own when you can just get the best equipment right from the shelf? What if you could get one of the best engines created by the most talented engineers in the world without raising a finger? Are you going to spend a year trying to make your own?

So basically, instead of doing everything yourself, you write down a shopping list of all the parts you need. And this is basically a gem file:

  • Rolls Royce Engine
  • AutoLive seat belts
  • Michellin tires.
  • Headlights PIAA Night
  • etc.

What my friend is basically your gem file!

+3
Mar 17 '16 at 12:07
source share

There may be many gems in your system ... so there may be several versions of the same gem .

A Gemfile indicates a list of gems with their versions that should be used / loaded / (set if not) whenever you run the rails application. or anything with bundle exec . . bundle exec . .

+1
Dec 28 '12 at 17:09
source share

First, what is a gem?

According to Wikipedia:

RubyGems is a package manager for the Ruby programming language that provides a standard format for distributing Ruby programs and libraries

Gemfile

A Gemfile is the file we create that is used to describe the dependency gem for Ruby programs.

Now in very simple words:

Gem can be thought of as a library that you can use in your code. Example: Faker Stone

Your code can use faker gem functionality to create fake data.

Now you can list all the gems your project requires in a gemfile. When you install the package, all the gems in your gemfile are installed for you.

0
May 11 '17 at 1:44
source share



All Articles