Skip to main content

What is gemfile.lock in rails?

What is gemfile.lock in rails?

What is Gemfile.lock? or What is the difference between Gemfile and Gemfile.lock? these are the common questions that you come across while starting development with Rails project.


What is Gemfile?

    Gemfile is the file in which you can mention which gems (kind of Third Party libraries) that you want to use for your Rails application
    Gemfile lists the gems that you want to use for your development
    Syntax:
        gem ‘rails'
            This mentions that gem with name ‘rails’ has to be used in Project context
    Whenever you bundle install, then bundler finds the gems listed in the Gemfile and it installs latest stable version for the gems listed in the Gemfile
    You can specify which version to be used for the rails development:
        gem 'rails', ‘3.0.5'
        This will install the specific version of the rails i.e. version 3.0.5
    You can read more regarding Gemfile here


What is Gemfile.lock?

    Gemfile.lock is created when bundler installs the specific version for the gems that are listed in Gemfile
    It records the version of the gem and name of the gem in file Gemfile.lock
    Thus, Gemfile.lock contains actual gem name with version with which your application was configured by the bundler
    Thus, Gemfile.lock is the file with actual gem version configuration
    Thus answer to what is gemfile.lock is - File with gems configured for your Rails applications along with the exact versions
    This file can be updated when you change gems listed in the Gemfile and also updating it using the bundler

Comments

Popular posts from this blog

Gem::LoadError (Specified 'mysql2' for database adapter, but the gem is not loaded. Add `gem 'mysql2'` to your Gemfile (and ensure its version is at the minimum required by ActiveRecord).?

Gem::LoadError (Specified 'mysql2' for database adapter, but the gem is not loaded. Add `gem 'mysql2'` to your Gemfile (and ensure its version is at the minimum required by ActiveRecord).) In rails?


1)change the gemfile in mysql version
 gem 'mysql2'

2)Change to mysql2 version
 gem 'mysql2','0.3.20'

Active Scaffold : Add radio buttons to your form ruby on rails ?

Active Scaffold : Add radio buttons to your form ruby on rails ?

The way to add radio buttons to your active scaffold create/update from is as shown below

#Controller

class UsersController < ApplicationController
active_scaffold :user do |config|
config.label = “Users”
config.columns = [:name, :gender]
config.columns[:gender].form_ui = :radio
config.columns[:gender].options[:options] = [['Male', '1'], ['Female','2']]
end
end

Get the Current url in ruby on rails

request.refererrequest.fullpathrequest.fullpath.split("?")[0]request.referer or request.env['HTTP_REFERER'] your controller to get the referer url. 

--------------------
request.original_url
request.url
request.host_with_port
<link rel="canonical" href="<%= request.url %>" />
<%=request.path%>
How can I get the current absolute URL in my Ruby on Rails view?
The request.request_uri only returns the relative URL.
request.env['REQUEST_URI']

 For Rails 3.2 or Rails 4 you should use request.original_url to get the current URL. More detail.

For Rails 3: You want "#{request.protocol}#{request.host_with_port}#{request.fullpath}", since request.url is now deprecated.

For Rails 2: You want request.url instead of request.request_uri. This combines the protocol (usually http://) with the host, and request_uri to give you the full address