Uninitialized constant ApplicationHelper::Twitter - ruby-on-rails

What's up guys?
I'm using the Twitter-Text gem in my RoR project, but I'm having troubles with the ApplicationHelper. I already see another topics with this same question on StackOverflow, but no one fix my problem.
Ok, let's take a look at my project:
Gemfile
gem 'twitter-text'
Application_Helper.rb
module ApplicationHelper
require 'twitter-text'
include Twitter::Autolink
include Twitter::Extractor
end
// I really don't know why I need create the following file:
helpers/twitter.rb
module TwitterText
end
helpers/twitter_helper.rb
module TwitterText
end
controller/posts_controller.rb
require 'twitter-text'
include Twitter::Extractor
What I see in localhost error page:
Routing Error
uninitialized constant ApplicationHelper::Twitter
Try running rake routes for more information on available routes.
What I see in my console:
ActionController::RoutingError (uninitialized constant ApplicationHelper::Twitter):
app/helpers/application_helper.rb:3:in `<module:ApplicationHelper>'
app/helpers/application_helper.rb:1:in `<top (required)>'
app/controllers/application_controller.rb:1:in `<top (required)>'
It's appear to be everything ok, what can I do to fix this trouble?
Thanks a lot!

whenever installing new gems you have to restart your web server as your gems are loaded when the application environment starts. Those are installed to your global gem directory by doing a bundle install.

Related

Simple error I think, but how can I require a gem installed file in one of my controllers? I get a LoadError

I installed the venice gem, which can be found here. https://github.com/nomad/venice
After installing the gemfile, it suggests using
require 'venice'
I have done this in my /api/v1/purchases_controller.rb class. Like this...
require 'venice'
class Api::V1::PurchasesController < ApplicationController
However, I end up getting the following error
FATAL -- :
LoadError (cannot load such file -- venice):
app/controllers/api/v1/purchases_controller.rb:1:in `<top (required)>'
Why is this. How can I use require this needed file in this one controller class (the only class I need it in).
In Rails applications gems are usually handled with Bundler.
Add the following line to your applications' Gemfile:
gem 'venice'
Then run bundle install in your console and restart your application.

Ruby Script API That Requires a gem

I have spent almost 8 hours on this and I know it's an easy fix.
I want to use this repository of the basecrm gem.
The problem: I don't know how to require/include the gem, neither locally as a cloned copy or as a regular "require gem_name" to find Leads
Ive download and put the gem files in /Users/username/Sites/basecrm/
and added the line below to my gem file.
gem 'basecrm', :git => 'git://github.com/basecrm/basecrm.git'
I ran "Bundle Install"
According to the Readme.md it says to call
require 'basecrm'
⌘ ~/Sites/basecrm/ irb
irb(main):001:0 require 'basecrm'
LoadError: cannot load such file -- basecrm
from /Users/username/.rbenv/versions/2.1.3/lib/ruby/site_ruby/2.1.0/rubygems/core_ext/kernel_require.rb:54:in `require'
from /Users/username/.rbenv/versions/2.1.3/lib/ruby/site_ruby/2.1.0/rubygems/core_ext/kernel_require.rb:54:in `require'
from (irb):1
from /Users/username/.rbenv/versions/2.1.3/bin/irb:11:in `<main>'
irb(main):002:0session = BaseCrm::Session.new
NameError: uninitialized constant BaseCrm
from (irb):2
from /Users/username/.rbenv/versions/2.1.3/bin/irb:11:in `<main>'
Any help is really appreciated. I am ready to tear my hair out on this.
If you use Gemfile you should run irb with bundler e.g. bundle exec irb and then require your gem require "basecrm"

I cant run my rspec in Ruby on Rails

I cant really get going with my Rspec-gem :) Unfortunately. It seems like the Rspec-rails gem works differently now? Any idea?
This is my error Im getting:
testing_rspec/spec/models/transport_spec.rb:2:in `<top (required)>': uninitialized constant Transport (NameError)
from /Users/yoniPacheko/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/rspec-core-3.0.3/lib/rspec/core/configuration.rb:1057:in `load'
My spec file:
require 'spec_helper'
describe Transport do
end
This is my file
Thanks for yr time!
If this is a newly-generated app, you should be using require 'rails_helper', instead of requiring spec_helper.
rspec-rails 3 has split the two out so that spec_helper can be used for standalone Ruby code, and rails_helper (which includes spec_helper) can be used for testing code that relies on Rails.

I keep getting a 'no such file to load' after installing the specific gem in Rails...why?

I get the following error:
no such file to load -- soap4r
But I have already done a gem install soap4r...multiple times to make sure.
Why am I getting this error and what can I do to fix it?
no such file to load -- soap4r
c:/Ruby187/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `gem_original_require'
c:/Ruby187/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `require'
I had the same problem in a Rails application when I included the soap4r inside the config block in environment.rb.
I got rid of the error when I moved it to the top of the file, before the initializer block.
This is what I have:
gem 'soap4r'
require 'soap/wsdlDriver'
This, inside the initializer block, gave me errors:
config.gem 'soap4r'

"uninitialized constant" when running RSpec tests with Rails 2.3.8 and Bundler

I just changed my Rails 2.3.8 project to load gems using Bundler, rather than the default Rails 2.3 loading mechanism. I followed the official instructions and the site runs fine in development. I use RVM for gem management, and have a specific gemset loaded for the application.
My RSpec test suite is unable to run, however. I have tried running both the entire suite and single tests using a variety of commands:
autospec # My usual way of running tests
rake spec
spec .
spec spec/models/comment_spec.rb # Trying a single spec file in isolation
ruby spec/models/comment_spec.rb
I have also tried running them all prefixed with bundle exec. Everything returns the same error:
/Users/casper/.rvm/gems/ruby-1.8.7-p248#darebusters/gems/activesupport-2.3.8/lib/active_support/dependencies.rb:440:in `load_missing_constant': uninitialized constant InheritedResources::Base (NameError)
from /Users/casper/.rvm/gems/ruby-1.8.7-p248#darebusters/gems/activesupport-2.3.8/lib/active_support/dependencies.rb:80:in `const_missing_not_from_s3_library'
from /Users/casper/.rvm/gems/ruby-1.8.7-p248#darebusters/gems/aws-s3-0.6.2/lib/aws/s3/extensions.rb:206:in `const_missing'
from /Users/casper/Projects/cf/darebusters/app/controllers/admin/base_controller.rb:1
from /Users/casper/.rvm/gems/ruby-1.8.7-p248#darebusters/gems/activesupport-2.3.8/lib/active_support/dependencies.rb:158:in `require'
from /Users/casper/.rvm/gems/ruby-1.8.7-p248#darebusters/gems/activesupport-2.3.8/lib/active_support/dependencies.rb:158:in `require'
from /Users/casper/.rvm/gems/ruby-1.8.7-p248#darebusters/gems/activesupport-2.3.8/lib/active_support/dependencies.rb:265:in `require_or_load'
from /Users/casper/.rvm/gems/ruby-1.8.7-p248#darebusters/gems/activesupport-2.3.8/lib/active_support/dependencies.rb:224:in `depend_on'
from /Users/casper/.rvm/gems/ruby-1.8.7-p248#darebusters/gems/activesupport-2.3.8/lib/active_support/dependencies.rb:136:in `require_dependency'
from /Users/casper/.rvm/gems/ruby-1.8.7-p248#darebusters/gems/rails-2.3.8/lib/initializer.rb:414:in `load_application_classes'
from /Users/casper/.rvm/gems/ruby-1.8.7-p248#darebusters/gems/rails-2.3.8/lib/initializer.rb:413:in `each'
from /Users/casper/.rvm/gems/ruby-1.8.7-p248#darebusters/gems/rails-2.3.8/lib/initializer.rb:413:in `load_application_classes'
from /Users/casper/.rvm/gems/ruby-1.8.7-p248#darebusters/gems/rails-2.3.8/lib/initializer.rb:411:in `each'
from /Users/casper/.rvm/gems/ruby-1.8.7-p248#darebusters/gems/rails-2.3.8/lib/initializer.rb:411:in `load_application_classes'
from /Users/casper/.rvm/gems/ruby-1.8.7-p248#darebusters/gems/rails-2.3.8/lib/initializer.rb:197:in `process'
from /Users/casper/.rvm/gems/ruby-1.8.7-p248#darebusters/gems/rails-2.3.8/lib/initializer.rb:113:in `send'
from /Users/casper/.rvm/gems/ruby-1.8.7-p248#darebusters/gems/rails-2.3.8/lib/initializer.rb:113:in `run'
from /Users/casper/Projects/cf/darebusters/config/environment.rb:9
from /Users/casper/Projects/cf/darebusters/spec/spec_helper.rb:5:in `require'
from /Users/casper/Projects/cf/darebusters/spec/spec_helper.rb:5
from spec/models/comment_spec.rb:1:in `require'
from spec/models/comment_spec.rb:1
I'm pretty sure the problem is not related to the Inherited Resources gem - I think gems are not loaded at all at this point, and Inherited Resources just happens to be the first one needed.
The thing that's baffling me is that /activesupport-2.3.8/lib/active_support/dependencies.rb:158 requires /app/controllers/admin/base_controller during the initialization phase. It shouldn't do that, and it certaintly doesn't do it in development mode. I can comment out gem 'inherited_resources' in my Gemfile, and site still runs. It's not until I hit an action that loads a controller that use Inherited Resources I get the "uninitialized constant" error.
For clarity, here's my Gemfile and spec_helper.rb.
Even older question, but I had the same issue with Bundler 1.0.3, Rspec-Rails 1.3.3 & Rails 2.3.8 and was able to boil it down to remarkable_rails. Remarkable-Rails seems to load rspec/rails before the initializers are run by the environment.
After adding :require => nil to it in the Gemfile and requiring it by hand in spec_helper AFTER requiring the rails-environment the issue disappeared.
I realize this is an old question, but I just came across the same problem.
I had the 1.3.0 version of rspec and rspec-rails required by my application. Looking at the rspec-rails changelog, I noticed there were a few bug fixes after 1.3.0. Upgrading rspec-rails to 1.3.2 fixed everything for me.
To fix this problem I changed by Gemfile from:
gem 'rspec-rails', '~> 1.3.2', :require => 'spec/rails'
to
gem 'rspec-rails', '~> 1.3.2'
and added the following to my spec helper
require 'spec/rails'

Resources