This perplexes me. A Mongoid::Criteria is not frozen, but if I assign it to a variable in console, it tells me FrozenError (can't modify frozen String: "#<Mongoid::Criteria
Why would that be, and how do I fix it?
mongoid (~> 7.3.0)
rails (~> 6.0.0)
I found this issue in IRB repo: https://github.com/ruby/irb/issues/136.
It means the issue was fixed in a later version of IRB, so my suggestion is to force IRB version higher than 2.8 to get the fix.
Just add gem 'irb', '>= 1.2.8' to your gemfile and test that it works with your current Ruby version.
I am getting the following error when I make a rest-client request:
<internal:D:/softwares/Ruby30-x64/lib/ruby/3.0.0/rubygems/core_ext/kernel_require.rb>:96:in `require': D:/softwares/Ruby30-x64/lib/ruby/gems/3.0.0/gems/mime-types-3.1/lib/mime/types/logger.rb:28: _1 is reserved for numbered parameter (SyntaxError)
Here is my code:
require 'rest-client'
response = RestClient.get 'https://www.linkedin.com/feed/'
puts response
Can anyone solve this one in return thanks for appreciation?
You are having a gem versioning issue. The error you are getting when you require rest-client is:
.../mime-types-3.1/.../logger.rb:28: _1 is reserved for numbered parameter (SyntaxError)
This is a problem in the gem mime-types, which rest-client depends on. Ruby introduced a change in syntax to support 'numbered parameters' in blocks that made _1, _2, ... reserved words. That change meant that people who had named variables matching that style (_1, _2, etc.) got a warning in Ruby 2.7. In Ruby 3.0 (which you are using), that now causes a syntax error.
The version of mime-types you are using (3.1) must have had code of that kind; it worked prior to Ruby 3.0, but now breaks. The good news is that the latest version of mine-types, 3.3.1, works with Ruby 3. You just need to update your gem:
D:> gem update mime-types
Updating installed gems
Updating mime-types
Fetching mime-types-3.3.1.gem
Successfully installed mime-types-3.3.1
If you are using bundler, you might need to change the version in your Gemfile and re-rerun bundle install to trigger the update.
For every require load error execute the below command to install gems for ruby programs.
ruby -S gem install <gem-name>
in my case it is.
ruby -S gem install rest-client
I have a rails-application (rails 5.2) with opal (0.11.1) running.
I would like to use erb-templates on client site. I followed the steps described in the official opal-docs (http://opalrb.com/docs/guides/v0.11.1/templates.html), but requiring the opalerb-file fails. sprocket claims the file could not be found:
couldn't find file 'views/user' with type 'application/javascript'
File views/user.opalerb exists.
It seems that sprockets does not handle / recognize opalerb-files, although I don't find a hint that things have to be configured.
How can I make opal with sprockets find and compile this file?
I ran into the same problem (Rails 5.2.2, Opal 0.11.4). The "opalerb" extension was not being correctly registered with Tilt and Sprockets. I addressed this locally by creating a file called "opal.rb" in config/initializers with one line:
require 'opal/sprockets/erb'
Alternatively, I was also able to fix the problem by explicitly including "opal-sprockets" in my Gemfile, pulling directly from the master branch in Github:
gem 'opal-sprockets', git: 'https://github.com/opal/opal-sprockets.git'
The final option seems to be to include "opal-haml" (even if you don't intend to use HAML). This seems to trigger initialization, although I haven't investigated why.
gem 'opal-haml'
I am trying to build an app in Rails. For my app I need to use the ns-api (dutch railways) in order to get from them the trains timetables. It exists as a gem (https://github.com/zilverline/ns-api) I use the bundler and I get the message that all the gems are ok, but when I am trying to create a controller it gives me the error that it does not recognise NSclient . This happens also when I use "require 'ns_client'" in my controller or in my configuration file. I think that although the bundler seems to work , the gem is not compatible with my Rails (ver 5.0.0) or my ruby version. Any way that I could solve this ?
I'm getting the following error:
Gem::Exception: can't activate hpricot (= 0.6.161, runtime),
already activated hpricot-0.8.3
0.6 is installed locally, 0.8.3 is frozen in my app.
This is my "stacktrace":
Loading production environment (Rails 2.3.10)
/software/ruby-ror-gem-1.3.1/lib/rubygems.rb:149:in `activate':Gem::Exception: can't activate hpricot (= 0.6.161, runtime), already activated hpricot-0.8.3
/e/app/www.example.com/rails/releases/20101117142713/vendor/rails/railties/lib/console_with_helpers.rb:5:NameError: uninitialized constant ApplicationController
How do I figure out which gem or library has a dependency on hpricot 0.6?
I've added the output of user438962's command below:
{"daemons-1.0.9"=>[],
"scgi_dp_rails-0.0.5"=>["preforkdp", "daemons"],
"rails-2.3.10"=>[],
"rwfd-0.1.0"=>[],
"nokogiri-1.3.2"=>["racc", "rexical", "rake-compiler", "hoe"],
"activesupport-2.3.10"=>[],
"rack-1.0.1"=>
["test-spec",
"camping",
"fcgi",
"memcache-client",
"mongrel",
"ruby-openid",
"thin"],
"rack-1.1.0"=>
["test-spec", "camping", "fcgi", "memcache-client", "mongrel", "thin"],
"preforkdp-0.1.2"=>["rwfd"],
"activerecord-2.3.10"=>[],
"hpricot-0.6.161"=>[],
"cgi_multipart_eof_fix-2.5.0"=>[],
"fastthread-1.0.1"=>[],
"gem_plugin-0.2.3"=>[],
"activeresource-2.3.10"=>[],
"ferret-0.11.6"=>["rake"],
"mysql-2.7"=>[],
"actionmailer-2.3.10"=>[],
"actionpack-2.3.10"=>[],
"hpricot-0.8.3"=>[],
"mongrel_upload_progress-0.2.2"=>["mongrel", "gem_plugin"],
"mongrel-1.1.3"=>
["gem_plugin", "daemons", "fastthread", "cgi_multipart_eof_fix"],
"mongrel_cluster-1.0.5"=>["gem_plugin", "mongrel"],
"rake-0.8.4"=>[],
"haml-2.0.9"=>[],
"remvee-mini_magick-1.2.3.4.0"=>[]}
If you use Bundler, you avoid this problem and you have the really great command : bundle viz
This Command generate a graph with all dependencies.
require 'rubygems'
require 'pp'
h = {}
Gem.source_index.each{|g, spec| h[g] = spec.dependencies.map{|d| d.name} }
pp h
I found that rfeedparser is the gem that uses hpricot 0.6.
The problem is that this version (0.6) works with rfeedparser, but emits the warning "Passing no parameters to XML::SaxParser.new is deprecated."
Well, with newer versions of hpricot (at least 0.8.2), this warning seems to have taken effect, because now having that version of hpricot or newer causes "ArgumentError: wrong number of arguments (1 for 0)" when calling FeedParser.parse(url).
Unfortunately, I've found that the only way to make this work with legacy Rails (we have a 2.2.2 app) is to uninstall any hpricot version that's not 0.6.
The issue will be that one of the gems you use depends on hpricot version 0.6.161
and so tries to load it, but that you already have hpricot-0.8.3 loaded. The more recent version might be loaded if you're using hpricot yourself, and have required hpricot for use without specifying a version. If that's the case, you can change your own require to be the same version as the other gem uses (0.6.161).
The other reason the more recent version of hpricot is being loaded, could be that another gem you use depends on that version of hpricot, meaning you can't use the specific versions of those two gems you have because they have clashing requirements for their hpricot version.
Use the methods other users have posted to help you track down the dependencies of the gems you are using.
You could try grepping your load path:
$:.each do |dir|
cmd = %(grep -r hpricot #{dir})
puts cmd
puts `#{cmd}`
end