Rails gemfile editing

孤街醉人 提交于 2019-12-23 22:17:02

问题


I'm starting a Rails tutorial that tells me to edit the gemfile when creating a new demo app:

source 'https://rubygems.org'

gem 'rails', '3.2.3'

# Bundle edge Rails instead:
# gem 'rails', :git => 'git://github.com/rails/rails.git'

gem :development do
gem 'sqlite3', '1.3.5'
end


# Gems used only for assets and not required
# in production environments by default.
group :assets do
  gem 'sass-rails',   '3.2.4'
  gem 'coffee-rails', '3.2.2'

  # See https://github.com/sstephenson/execjs#readme for more supported runtimes
  # gem 'therubyracer', :platform => :ruby

  gem 'uglifier', '1.2.3'
end

gem 'jquery-rails', '2.0.0'

group :production do
    gem 'pg', '0.12.2'
end

# To use ActiveModel has_secure_password
# gem 'bcrypt-ruby', '~> 3.0.0'

# To use Jbuilder templates for JSON
# gem 'jbuilder'

# Use unicorn as the app server
# gem 'unicorn'

# Deploy with Capistrano
# gem 'capistrano'

# To use debugger
# gem 'ruby-debug19', :require => 'ruby-debug'  

When I try to bundle install the file, using bundle install --without production, as per the instructions, I get this error:

You need to specify gem names as Strings. Use 'gem "development"' instead.

When I return to the file and change gem :development into gem "development" I'm instead told:

Could not find gem 'development (>= 0) ruby' in the gems available on this machine.

I'm new to this and really have no idea what to do when one set of clear instructions seems to clash with another and neither works, especially because I don't really understand what any of these terms mean.

Help would be very much appreciated,


回答1:


:development should be a group, not a gem. Try with this:

group :development do
  gem 'sqlite3', '1.3.5'
end

This means that all the gems inside the development group should be loaded in the development environment. In this case, you won't have the sqlite gem when running in production or test.

The same applies to the production group.

The assets group is loaded only when compiling the assets for the Asset Pipeline.



来源:https://stackoverflow.com/questions/10762590/rails-gemfile-editing

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!