Undefined constant "RestClient" after rest-client gem has been installed - ruby-on-rails

Just added gem "rest-client", "~> 1.6.7" to my gem file and ran bundle install.
Trying to make the app send a get request to a local jetty
#server = "http://127.0.0.1:3333"
RestClient.get #server+'/command/core/get-version'
results in
uninitialized constant XController::RestClient
UPDATE:
Question solved, I forgot to restart the webserver.

The problem is that it requires to restart the server for freshly installed gems to come in effect.

Outside rails, I ran into the same problem. Solution:
require 'rest-client'

It happened to me few times i named the gem restclient instead of rest-client :) Both gems exist, but the one with dash is the correct one.

Related

Ruby error: cannot load such file -- rest-client

I am using Ruby on Rails 4.
I am trying to
require 'rest-client'
in my controller so that I can parse the login information I am getting from a form and send it to an API.
I can verify that the gem is installed and is also in my Gemfile on the application root.
However, it is still throwing the "cannot load such file -- rest-client " when I try to require the file in my controller.
I have googled the error and most of the answers I saw were either the gem wasn't installed, wasn't in the Gemfile, or a combination of both those. Neither is the situation here.
Is my controller unable to access the rest-client gem for some reason? I have to use rest-client because it is required in the API.
This is the line I used to install the gem:
gem install rest-client
This is the homepage of the gem: https://github.com/archiloque/rest-client
Which just redirects you to https://github.com/rest-client/rest-client
I should also note that it works fine when I wasn't using the code in a Rails project but just running the commands in the Terminal.
Assuming you're using https://github.com/rest-client/rest-client (since you didn't specify), your require line should be
require 'rest-client'
according to the README. Also, make sure you restart your rails server after adding the gem to your Gemfile and running bundle.
Run the following command in your terminal:
gem install rest-client
and use require 'rest-client'. No need to change to rest_client.
in my case, none of the solutions in this thread worked
what did work, was to add the gem directly in the Gemfile:
gem 'rest-client'
after closing the rails server, exiting rails console and running bundle install,
I opened again the rails console and this time require 'rest-client' worked flawlessly
For me it was an issue with bundle (which I thought I had installed). Spoiler alert, I didn't, and this is how I fixed it. I'm on a Mac running OS X Yosemite and my terminal version is Darwin Kernel Version 14.3.0:
cd
gem install bundler
or
cd
sudo gem install bundler
If you get something along the lines of the following error:
ERROR: While executing gem ... (Gem::FilePermissionError)
You don't have write permissions for the /Library/Ruby/Gems/2.0.0 directory.
Finally, change your require line from:
require 'rest-client'
to
require 'rest_client'
Then run your code!
First ensure you have installed gem 'rest-client', ~> 1.8.0 on your gem file. Run bundle install and then require 'rest_client'. This worked for me.
Try require 'rest_client', instead of require 'rest-client'

exception_notification gem raises ActionView::Template::Error (code converter not found (UTF-8 to UTF-16)) only on Heroku production mode

I create rails app deployed on Heroku.
also, exception_notification gem enabled.
when it is on development setup ActionMailer to Gmail,
everything is fine and sends a notification from Gmail address.
but when it comes to production environment on Heroku,
I get following error when server trying to send a email.
ActionView::Template::Error (code converter not found (UTF-8 to UTF-16))
Could anyone tell me what's happening here?
The issue was raised on the main repository (see here), but so far was not addressed.
You might want to take a look at this fork to the exception_notification gem, specifically this commit which tries to deal with the problem:
https://github.com/alanjds/exception_notification/commit/048fc6be972189e62ca3b9453d19233ec5773016
To use this fork I pointed the gem to it, like so:
Gemfile:
gem 'exception_notification', git: 'git://github.com/alanjds/exception_notification.git'
This solved the issue for me.
Quick adjustment to solution by hananamar, otherwise you'll get an error:
gem 'exception_notification', :git => 'git://github.com/alanjds/exception_notification.git', :require => 'exception_notifier'
I know this is an old post but since I got the same issue some days ago, I wanted to share here that I solved it by forcing the latest version of the gem on my Heroku app.
gem 'exception_notification', '3.0.1'
I guess the problem was with version 3.0.0 and it is fixed on 3.0.1.

Mimetype-fu isn't working

I feel like this should be an easy answer but I'm totally stumped.
I've added mimetype_fu to my gemfile and it installed it when I ran bundle install. When I try to use File.mime_type? in my application I get an error:
NoMethodError: undefined method `mime_type?' for File:Class
In the rails console when I run
gem 'mimetype-fu'
it returns true
I'm on windows, if that matters
Any ideas?
If you are using Bundler, you can also just add require to the gem line like this.
gem 'mimetype-fu', :require => 'mimetype_fu'
You may need to manually require it inside your rails app. You can do this by adding an file to config/initializers/ if you want it to be available globally.
EDIT | Also, you did restart the rails server, right? ;)

Trouble including httparty in ruby on rails

I've been trying to use HTTParty in my rails code
sudo gem install httparty
From the command line I can now successfully do
httparty "http://twitter.com/statuses/public_timeline.json"
When I try this in my rails app
require 'rubygems'
require 'httparty'
class FooController < ApplicationController
include HTTParty
def bar
blah = HTTParty.get("http://twitter.com/statuses/public_timeline.json")
end
end
I get the error message "no such file to load -- httparty"
I suspect there is something wrong with my environment?
You don't need to do 'include HTTParty' inside the Controller. Just remove that and it should work. I just tested it and it worked for me. If this doesn't work for you, you should add the gem to your environment.
Usually if you use a gem inside your Rails application, you should add the following to environment.rb:
config.gem "httparty"
The gem will be available in the application now and you don't need to add 'require' inside the Controller. Also, you don't need to require RubyGems inside a Controller.
When you use Rails 3, you need to put the following inside the Gemfile:
gem "httparty"
I hope it works for you. :)
The problem is, if you load a new gem, you have to restart the server even if you are in development.
I had this same error. I tried moving the require HTTParty all over, but found, all I needed to do was restart the rails server In the end I did not need to 'require HTTParty' nor 'include' it. It just needed to be loaded into rails.
1)include the httpary in your gemfile
open your gem file then add
gem 'httparty','YOUR VERSION NUMBER'
2) run bundle install in your command prompt of the app file
3) restart the server
Ran into the same problem. Then I switched from Ruby 1.8.7 to Ruby 1.9.2 and all errors varnished into thin air.
(Yes, it first took me quite some hours to come up with the possibility that the Ruby version might be the problem. Configured a secundairy server to avoid possible conflicts with 2 ruby versions, and after way to many hours I got my RoR stack up and running. And the first test with httparty (based on the example on top) worked out of the box! Finally can sleep RESTfully again :-)
I run into the same error whilst reviewing a project from a student, I change the name of the Gem from uppercase to lowercase then run bundle install. I then went ahead to change the format in which they were being imported from
require 'HTTParty' to require 'httparty' and boom it worked

Problem installing googlecharts gem?

I am trying to use the googlecharts gem to create some quick charts. Here are the rubyforge and github sites:
http://googlecharts.rubyforge.org/
http://github.com/mattetti/googlecharts/tree/master
After installing, I keep getting an error saying "no such file to load -- googlecharts" even though when I do a "gem list", the gem is listed. I have restarted my server. Anyone know what could be going on here?
Thanks!
According to the docs, you need to
require 'gchart'
but it sounds like you might be doing
require 'googlecharts'
instead.
You must do a gem install googlecharts first and then add gem "googlecharts" to your gemfile, then run bundle install. You should be free from the error afterwards.

Resources