简体   繁体   中英

Getting started with Nokogiri in Rails? No need for gem 'nokogiri'?

I'm just looking into Nokogiri and was thinking about using it in my app, but apparently when I do bundle install (without gem 'nokogiri' ) it's already " Using nokogiri 1.6.7.1 ".

When I add gem 'nokogiri' in my Gemfile, there's no "installing..." So, is nokogiri already pre installed in Rails? If so, do I still have to require these:

require 'nokogiri'
require 'open-uri'

Where do I put this? Within my controller? or application.rb ?

This is my application.rb looks like

require File.expand_path('../boot', __FILE__)

require 'rails/all'

Bundler.require(*Rails.groups)

if Rails.env.test? || Rails.env.development?
  CONFIG = YAML.load(File.read(File.expand_path('../aws.yml', __FILE__)))
  CONFIG.merge! CONFIG.fetch(Rails.env, {})
  CONFIG.symbolize_keys!
end

module App
  class Application < Rails::Application
    config.middleware.use Rack::Pjax
    config.active_record.raise_in_transactional_callbacks = true
    config.active_job.queue_adapter = :sidekiq
  end
end

Nokogiri is required by another gem ( rails-dom-testing ). So it's already installed.

And you don't need to write require 'nokogiri' statement. Because Rails uses Bundler to manage dependencies and load gems. Nokogiri will be already loaded.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM