I have written my own Gem called date_ninja which makes sure a date is returned in the correct when passing a date from excel. Testing the gem it works fine. For example opening irb, and calling require 'date_ninja' returns true and I am able to use.
DateNinja::DateDojo.date_format_validation(value).
This will either return an date or an exception.
In my Rails App, I have added the gem to my gemfile as so:
gem 'date_ninja', git: 'git#github.com:mpowered/date_dojo'
I then ran bundle install but when I use it, I get this:
DateNinja::DateDojo.date_format_validation(56423)
NameError: uninitialized constant DateNinja::DateDojo
from (pry):5:in `<main>'
If I open the Rails console and see if I can require 'date_ninja' it => false so I am guessing its not loading my gem even though I have bundled it. Am I missing a step?
Can you try replacing the line:
gem 'date_ninja', git: 'git#github.com:mpowered/date_dojo'
with
gem 'date_ninja', path: 'local/path/of/ninja'
If this works then something is not well set with git.
Related
I get the following error when I try to start up rails or if I run rails console.
.rvm/gems/ruby-2.3.3#adventure_map/gems/godmin-tags-1.0.1/lib/godmin/tags/helper.rb:11:in '<module:Godmin>': uninitialized constant Godmin::FormBuilders (NameError)
I have included the gem godmin-tags , using haml for templating and running rails-5.0.1
No issue has been raised on its github page and I can seem to find a solution to this
Part of my Gemfile is:
gem 'godmin-tags'
gem 'godmin' # administrative interface https://github.com/varvet/godmin
gem 'devise_token_auth'
gem 'omniauth'
Make sure you include godmin-tags after godmin ;-)
I'm using a gem for gmail in my Rails app. My Gemfile contains:
gem 'gmail-api-ruby', :require => 'Gmail'
And in my controller, I initialize the gem with (using devise/omniauth to get the refresh_token from Google):
Gmail.client_id = ENV['CLIENT_ID']
Gmail.client_secret = ENV['CLIENT_SECRET']
Gmail.refresh_token = current_user.refresh_token
This works fine in development, but when I deploy to Heroku, I get the following error:
/app/vendor/bundle/ruby/2.2.0/gems/bundler-1.7.12/lib/bundler/runtime.rb:76:in `require': cannot load such file -- Gmail (LoadError)
I cannot figure out why. Should I be requiring the gem somewhere else in my app?
Ruby 2.2.0
Bundler: 1.8.5
Rails: 4.2.0
require is case sensitive if the underlying filesystem is case sensitive (which it is on linux, which is what underpins heroku)
Change to :require => 'gmail' instead of Gmail and you should be ok.
Just remove useless require option from your Gemfile because bundler can load classes inside of this gem without specify require option in your case.
gem 'gmail-api-ruby', '~> 0.0.10'
and run bundle install.
FYI: read section about require option here.
I want to use Coveralls.io for my gem Headhunter that I'm developing at the moment. The doc says, I should simply add
gem 'coveralls', require: false
to the project, but as far as I know, this isn't the right way to load gems within another gem. Instead, stuff like that should happen in the .gemspec file. So I tried to add it like this:
s.add_development_dependency('coveralls', '>= 2.0')
But this doesn't work - it breaks my gem's whole functionality:
$ rake
/Users/josh/.rvm/rubies/ruby-2.0.0-p353/bin/ruby -S rspec ./spec/headhunter/css_hunter_spec.rb ./spec/headhunter/css_validator_spec.rb ./spec/headhunter/html_validator_spec.rb
/Users/josh/Documents/Work/MuheimWebdesign/headhunter/lib/headhunter/css_validator.rb:6:in `<class:CssValidator>': undefined method `full_gem_path' for nil:NilClass (NoMethodError)
This is the file that breaks:
require 'net/http'
require 'nokogiri/xml'
module Headhunter
class CssValidator
VALIDATOR_PATH = Gem.loaded_specs['headhunter'].full_gem_path + '/lib/css-validator/'
So Gem.loaded_specs['headhunter'] isn't available anymore, no idea what's going on here.
What's wrong here?
I was wondering the same and I just got it working.
You need to add:
spec.add_development_dependency "coveralls", "0.7.0"
to your .gemspec (0.7.0 is the coveralls gem latest version as the time of writing this)
make sure to run bundle installsuccessfully
and add:
require 'coveralls'
Coveralls.wear!
to the beginning of your spec_helper.rb or test_helper.rb, before requiring anything else.
Hope this helps.
I'm bewildered here. While I can run require "gmail" in irb and successfully load the Gmail gem, doing so in my rails console returns false. I made sure to include all the directories in $LOAD_PATH for irb in the $LOAD_PATH for my console, but still cannot get the gem to load in my console.
It may be that the gmail gem is conflicting with another gem that I have installed, but I don't know how to confirm this. It seems other people have had similar problems:
Why is autoload failing to load files for gems
Ruby autoload conflicts between gmail and parse_resource gems
Rails: Using ruby-gmail gem causes problems
I made sure to include 'gem "gmail"' in my Gemfile and run bundle install. Still no luck!
Stuck here, so would appreciate any help.
false doesn't mean that the gem is failing to load, it means that the gem is already loaded.
It the rails console could not find the gem you would get a LoadError. Here's an example of an app of mine that has gem 'haml' in the Gemfile.
1.9.2p320 :001 > require 'haml'
=> false
1.9.2p320 :002 > require 'foo'
LoadError: no such file to load -- foo
Another way to see this is to require 'gmail' a second time in your irb session.
You must add this line to your Gemfile:
gem 'gmail'
This is because the gems loaded by your application are restricted to just the ones specified inside the Gemfile, and their dependencies (and the dependencies of the dependencies, and so on).
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? ;)