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? ;)
Related
I am trying to use this gem in my rails application, but when I add it to my gem file and try to use it I get an error saying that it did not found the methods required (I am using it inside a controller). Also require 'bn4r' does not help as rails tells me that it cannot load such a file, which is odd. I can access the library from the development console with no problems any idea as to why this happens?
After adding the gem to the Gemfile:
gem 'bn4r'
install it:
$ bundle install
Restart the server and use it like this:
BayesNet.new
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.
I've added the delayed_job gem to my gemfile and installed correctly but when I try to run the following line:
Delayed::Job.enqueue do_it(), 0, 1.minutes.from_now.getutc
I get the error 'uninitialized constant Delayed::Job'
Can somebody explain what i need to do here? I've tried running 'rake jobs:work' beforehand but it also returns the 'uninitialized constant Delayed::Job' error. Additionally, I've added "require 'delayed_job'" to the file (application.rb) without much luck.
If you've upgraded to delayed_job version >=3 you'll need to add this (presuming you're using ActiveRecord):
# Gemfile
gem 'delayed_job_active_record'
Did you follow the installation instructions on the README file? https://github.com/collectiveidea/delayed_job
Add this to your gemfile:
gem 'delayed_job_active_record'
and then run this at the console:
$ rails generate delayed_job:active_record
$ rake db:migrate
You need to create the delayed jobs table in the database (this assumes you're using active record).
For Rails 3, all you need to do is include it in the gemfile, run that code above to create the table and migrate the database, then restart your server and go!
I'm using delayed job within an engine (so the gem is specified in a .gemspec rather than Gemfile) and was getting the same error. I found that I could solve the problem by using:
require 'delayed_job_active_record' # fixes problem
rather than
require 'delayed_job' # doesn't
Just in case, if this is still unanswered, check the below link
http://www.pipetodevnull.com/past/2010/4/14/uninitialized_constant_delayedjob/
edit: Alternative, just upgrade to the latest version - 2.1
i was struggling a while back with the same problem. i was following ryan bates screencast on delayed_job and got the same error 'uninitialized constant Delayed::Job'. In the screencast ryan creates a file called mailing_job.rb(located under lib folder) with the delayed_job perform method inside, which allows you to use the enqueue method. After doing some research i found that rails 3 does not automatically load the lib folder files into your app.(not entirely sure)
Try this
In your controller where you use this:
"Delayed::Job.enqueue do_it(), 0, 1.minutes.from_now.getutc"
Try to require the file like this.
require 'mailing_job'
class AssetsController < ApplicationController
def some_method
Delayed::Job.enqueue do_it(), 0, 1.minutes.from_now.getutc
end
end
Version change possibility : if you jump from the 2.1.x to the 3.x version of the gem via a non locked down bundle, you may have a similar issue.
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.