Rails NoMethodError (undefined method `new' for Hyperclient:Module) - ruby-on-rails

This is quite a 'newbie' question but I've been searching and can't seem to find anything to solve an error with using hyperclient in a rails app, in one of my Model's methods.
Whenever I run rails c I get the error
NoMethodError (undefined method `new' for Hyperclient:Module)
In my gemfile
gem "hyperclient"
-- ran bundle install
in model app/models/artwork.rb
class Artwork < ApplicationRecord
require "hyperclient"
def self.test_artsy
api = Hyperclient.new('https://api.artsy.net/api') do |api|
puts api
end
end
end
I've looked at the docs on hyperclient and have seen that they do have a method for .new (also on their examples) so I know it's something I've done incorrectly but I'm not sure what else to try?
The code did work when opening irb in the terminal.

You haven't specified any version in your Gemfile so it might happen that Bundler will not install the latest version and that's what I am guessing might happened here.
You can check which version is installed by doing:
cat Gemfile.lock | grep hyperclient
You have at least two options here:
1)
bundle update hyperclient - this should update your Gemfile.lock to the latest version
2)
bundle remove hyperclient
bundle add hyperclient --version "0.9" - this will update your Gemfile and then run bundle install that will regenerate your Gemfile.lock
The second option is recommended since it is a good practice to always specify version for the gems you are using.

Related

Devise Ruby Gem NameError when installing

I was trying to install the Ruby Gem Devise and I stupidly overlooked a step. I included the gem in my gemfile then ran the bundle install on the prompt. Then I forgot to run the generator rails generate devise:install.
Then when I went to generate my User model it came up with the following error C:/RailsInstaller/Ruby2.2.0/lib/ruby/gems/2.2.0/gems/activesupport-5.1.4/lib/active_support/inflector/methods.rb:269:inconst_get': uninitialized constant User (NameError)`
I've tried uninstalling the gem and removing anything that refers to Users and reinstalling the gem but it keeps coming up with the same error.
I'm hoping someone can maybe shine a bit of light on this issue
I've just fixed the issue. When you run the bundle install command, it automatically configures the routes folder, so I've removed any reference to devise and it's worked now

Geokit issue - "could not find generator"

I am trying to get started with Geokit, and I ran the install command and was greeted with the following:
rails g geokit_rails:install
Could not find generator geokit_rails:install.
Any idea what's going on? I am so confused. bundle install works just fine. I run bundle exec rake db:migrate. but when I go into the console, when I try require 'geokit', I get false. I assume it's because the config file is missing? But how do I generate a sample config file to modify if the install script is failing??
The problem is that your version of the geokit-rails gem does not contain the generator. It was added with https://github.com/geokit/geokit-rails/commit/bb4261acef62a26de823c4b7306634ffb7c3381f. The latest version of the gem is 2.1.0, and as you can see here, the generators were not part of that release.
If you want to use the head version of the gem, then you can change your Gemfile to match gem 'geokit-rails', github: 'geokit/geokit-rails'.

undefined method `action_mailer' during Capistrano deployment

I'm having this error message come up during Capistrano deployment. It implies to me that something's wrong with Rails being installed or something? Rails is not currently installed on the server side, but it's in my Gemfile (and my Gemfile.lock), so I'm assuming it should be installed during the bundle install command that gets executed before this line.
The actual command that's giving the error is:
bundle exec rake RAILS_ENV=production RAILS_GROUPS=assets assets:precompile
I guess the problem is just that Rails is not being installed during the bundle install. Am I missing something?
Thanks!
UPDATE 1: Rails appears to be installing correctly via the bundle install command. If I check out the directory .../shared/bundle/ruby/1.9.1/gems, I can see action mailer in there.
UPDATE 2: Running the command rake assets:precompile actually fails locally as well, so this doesn't have anything to do with Capistrano it would appear. Now I just have to figure out why the config object doesn't know anything about action mailer?
UPDATE 3: Hot on the trail. It looks like my installed version of actionmailer is 0.6.1 (?!), meanwhile all the rest of my Rails stuff is up at 3.2.9. bundle update refuses to update actionmailer past this version. I'm going to remove all of my gems and start fresh.
UPDATE 4: Deleted my entire gemset using rvm gemset empty. Then tried to run bundle again, and again it tries to get actionmailer 0.6.1. I think something is screwed up with bundler or something...
The problem ended up being that I had removed a dependency upon a specific version of Rails in my Gemfile. I just had gem "rails" in there. That seemed to completely botch the dependency calculations, because it was getting super-old versions of action mailer rather than getting a consistent version from all gems. Guess it's a bad idea to not specify an exact Rails version. Yikes!
#aardvarkk,
Thanks for posting this issue, I was having the same error with my installation of Rails 4.0.0 and the error was preventing me from running my rails server
This is while I'm trying to follow the Hartl Tutorial for RoR.
I added gem "rails", '4.0.0' to my gem file and now I'm able to run my rails server.
Thank you

Rails 3.2.7 and Spree 1.1.2. When I try to access CART, there is debug info show that "undefined method `password_salt=' .."

I installed rails on Windows7 using RailsInstaller (v2.1.0). I found the original rails was v3.2.1. After that, I "gem install spree". It seems the installation upgrades rails to v3.2.7. I mentioned that because before yesterday it was just 3.2.6. Every thing goes well under rails 3.2.6, but if I "spree install" a rails 3.2.7 app, I failed to access the default store's Cart. And get the error like this:
NoMethodError in Spree::OrdersController#edit
undefined method `password_salt=' for #<Spree::User:0x68438d0>
As I checking the database, yes, there is no "password_salt" but only "salt" in spree_users table.
Is there anyone else encountered this problem? I had taken almost half day on this problem. Did I miss something in the Spree path?
Thanks very much.
I think I had the exact same issue before, see if specifying spree gem version (assuming is 1.1.2) in the Gemfile and then running bundle update works
#Gemfile
gem 'spree', '1.1.2'
and later run
bundle update
See if it works!

Rspec testing fails with "NameError: uninitialized constant ActionController::TestCase::Assertions"

I am working on a sample RoR app and I am having trouble testing it with rspec. I have rspec installed and running the tests however they are failing and I don't know why. I run the command:
bundle exec rspec spec/
And when I run this; this is the error message I get:
Failures:
1) PagesController GET 'home' should be successful
Failure/Error: Unable to find matching line from backtrace
NameError:
uninitialized constant ActionController::TestCase::Assertions
# /usr/lib/ruby/vendor_ruby/action_controller/integration.rb:18
# /usr/lib/ruby/gems/1.8/gems/webrat-0.7.1/lib/webrat/integrations/rails.rb:2
# /usr/lib/ruby/gems/1.8/gems/webrat-0.7.1/lib/webrat/core/configuration.rb:105:in `mode='
# /usr/lib/ruby/gems/1.8/gems/rspec-rails-2.6.1/lib/rspec/rails/vendor/webrat.rb:26
# /usr/lib/ruby/gems/1.8/gems/webrat-
And alot more error messages.
I'm no expert on RoR and would really appreciate help. Thanks in advance.
RSpec is only guaranteed to work out of the box for Rail defaults. Remove webrat from your Gemfile and try it again.
Depending on the tutorial this might break things again in later steps.
My solution to the problem was to remove the package installation of rails (apt-get remove rails && apt-get autoremove) and its dependencies, because it was apparently clashing with the gem install. Quite understandable. You can install it with gem (sudo gem install rails)
I had the same problem on a fresh Ubuntu 11.10 install.
After ensuring I was using the latest versions of rspec and that rails was installed using
gem install rails
I also ensured that uninstalling the ubuntu rails didn't leave any artificts with
sudo apt-get autoremove
I also had ruby 1.8.7 so I switched to 1.9.2
rvm use 1.9.2
Either my ruby version was the problem or the autoremove removed some interference. But things were working after that.

Resources