I'm trying to install the calendar_helper gem. I included the gem in my Gemfile:
gem 'calendar_helper'
I ran bundle install and loaded fine.
Using calendar_helper (0.2.4)
0.2.4 is the newest version in GitHub, so that looks good. I'm running on Pow so I don't need to restart the server (though I tried that anyway). Adding a call to the method calendar throws an error:
undefined method `calendar'
I feel like something could be wrong with my Rails installation or something. Any ideas?
It doesn't look like version 0.2.4 is up-to-date with what's on github; it's missing the subclass of Rails::Engine necessary to load the helper. The key line on the edge source is here: https://github.com/topfunky/calendar_helper/blob/master/lib/calendar_helper.rb#L231.
You may be able to fix this by installing the gem from edge:
gem 'calendar_helper', :git => 'git://github.com/topfunky/calendar_helper.git'
Edited:
If that still isn't working, you can also try this in your ApplicationHelper:
require 'calendar_helper'
module ApplicationHelper
include CalendarHelper
end
Related
I am developing a gem meant to be used with Rails projects and want to try it out locally with another Rails app of mine.
I built the gem with bundle exec rake release which put a .gem file in the /pkg directory.
Then, in my Rails app, I added the following to my gemfile
gem 'mygem', '0.1.1', path: '/Users/me/projects/mygem/ruby/pkg'
I then ran bundle install which said it installed the gem. When I do this, it removes the gem from the path. IDK where it went.
When I start the Rails app, it's like the gem isn't included at all.
Interestingly, if I add a version that doesn't even exist, it still says bundle install works fine. (Example: gem 'mygem', '0.1.2345', path: '/Users/me/projects/mygem/ruby/pkg')
What am I supposed to do to try out my Gem locally with a Rails app?
This question is different from How can I specify a local gem in my Gemfile? because I explicitly tell bundle in my Gemfile to use the local gem, with the path given, and it still doesn't work. When I run bundle install, it says
Using mygem 0.1.1 from source at /Users/me/projects/mygem/pkg
So you'd think it works right, but it still doesn't.
Interestly, if I try it with a version number that doesn't exist, like mygem 1.2.3, it still runs bundle install successfully, which is really weird and seems like a bug:
Using mygem 1.2.3 (was 0.1.1) from source at /Users/me/projects/mygem/pkg
I prefer to use the following when working on a local gem side-by-side with a Rails project:
gem 'foo',
:git => '/path/to/local/git/repo',
:branch => 'my-fancy-feature-branch'
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'
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? ;)
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
I am attempting to get a gem I installed working in a Rails application. I can require the gem just fine in a Ruby program that I run from the command line using:
require 'nokogiri'
But when I attempt to do the same in one of my Rails controllers it errors saying "no such file to load -- nokogiri".
I tried using the full path to the lib/nokogiri.rb file, but that fails because it cannot find "nokogiri/native".
Better, place the following in your environment.rb file:
Rails::Initializer.run do |config|
...
config.gem :nokogiri
...
end
This will tell Rails that you depend on that particular gem. It also allows you to specify particular versions, and it will automatically keep all your gems synched, or unpack them into vendor/gems if you so wish.
I had a similar error but simply forgot to put the following in my environment.rb file: (note the quoted "nokogiri")
Rails::Initializer.run do |config|
...
config.gem "nokogiri"
...
end
Ok I figured it out. This is going to sound pretty stupid...but oh well...
It turns out I had two installations of ruby on my machine. I use InstantRails to serve my test applications and it comes prepackaged with an installation of ruby. I had another installation however outside of this and it was here that nokogiri had been installed, not in the installation in InstantRails.
In any case they were looking in different spots for the gems.
Try the following
require 'rubygems'
gem 'nokogiri'
If you are on some form of *nix then did you get any errors when you installed the gem, particularly errors stating that the gem was not on the path. This may happen if you have installed the gem as yourself rather than as root and you do not have your personal gem library in your gem path.
If you always install your gems using
sudo gem install some_gem_name
then you should not get that problem.