NameError in WelcomeController#index on RubyOnRails - ruby-on-rails

I got this error
NameError in WelcomeController#index
uninitialized constant YouTubeIt
Rails.root: C:/Sites/rails_code/youtube
Btw i checked the gem author github, checked sintax of constant, seems everything's alright, so i can't figure it out.
There is a very similar question here:
Uninitialized constant SO
But in his case, there was a typo, i don't have any typo, i even checked the tutorial like 6 times, but there's no apparent error on my side, here's my controller code:
class WelcomeController < ApplicationController
def index
#cliente = ::YouTubeIt::Client.new(:dev_key => "AI39si4Ao5BFsYIkbzko7b9A_iktB2Pc8DAblJJ_JzJx6IL6Mju1dYYkMKY6TByz8MJPXfm4__tCAt9Is6Mvjg2JM55kuJVVqQ")
#videos = #cliente.videos_by(user: "AlbertoMaso2")
end
end
already installed the youtube_it and declared it's presence in the app by adding it to the Gemfile.
I'm stuck on this one and can't get it to work.
Anyone can shed some light upon this?
Thanks in advance!

When you have changed Gemfile, or added a new gem to it, please, make sure that you have updated Gemfile.lock also. To update lock file just run bundle install command.
Then in order to check usability the gem, you could not run whole rails server, but simply rails console with loaded development environment. Do it as follows:
$ rails c
or
$ rails console
Then inside the IRB, you can try your new gem features, in your case as follows:
irb(main):001:0> require 'youtube_it'
=> true
irb(main):002:0> YouTubeIt
=> YouTubeIt

What happens if you change
#cliente = ::YouTubeIt::Client.new...
to
#cliente = YouTubeIt::Client.new...

Related

Call Method in Gem from Rails Model

I've installed the name_of_person Gem into my Rails project.
This gem contains a method named full (source).
I have a Rails model named Film that contains a class named foo.
I want to call full from within foo, like so:
class Film < ApplicationRecord
def foo
name = NameOfPerson::PersonName.full("David Heinemeier Hansson")
end
end
When I try this I get this error: uninitialized constant Film::NameOfPerson.
I know I'm totally misunderstanding something basic about Ruby here. Please help.
Thanks #dbugger who helped me solve this one.
The problem appears to have been that the Rails gem wasn't installed correctly.
I uninstalled and re-installed the gem, and then I rebooted my Rails server. As soon as I did so both name = NameOfPerson::PersonName.full("David Heinemeier Hansson") and ::name = NameOfPerson::PersonName.full("David Heinemeier Hansson") work fine.
Thanks!

ApiAuth gem + ActiveResource

I'm trying to get ApiAuth working with ActiveResource and having no luck. The documentation suggests this as the way to use the gem:
class Foo < ActiveResource::Base
with_api_auth("foo", "bar")
end
This results in the following error:
NoMethodError: undefined method `with_api_auth' for Foo:Class
I know that the api_auth library is available because when I do
require 'api_auth'
i get "false", which I believe means that the library/gem was already loaded.
Additionally, I picked out the module/class where with_api_auth is defined and don't get an error:
2.3.8 :004 >
ApiAuth::Rails::ActiveResourceExtension::ActiveResourceApiAuth
=> ApiAuth::Rails::ActiveResourceExtension::ActiveResourceApiAuth
2.3.8 :005 >
I found a couple issues for this exact error on the api_auth github project, but neither had solutions that worked for me.
Anyone else see this error or know how to eliminate it?
So in the end it was an ordering of gems in my Gemfile that made the difference. It ended up being an ordering issue in my Gemfile. I found an issue (113) on the gem github issues list that said to make sure the order was right by doing:
gem 'activeresource'
gem 'api-auth'
Originally this hadn't worked and it ended up being because you no longer have to explicitly put activeresource in your Gemfile. So I moved gem 'api-auth' the last line in my Gemfile and everything worked.
I don't know for sure, but I think it has to do with how mixins are loaded on bundle install. "think" being the most important word in that statement.

Using Asciidoctor in Rails

i tried to use asciidoctor gem in my rails app. I added it to my Gemfile and made bundle install.
Now i try to use asciidoctor within a Controller:
def show
#article.text = Asciidoctor.render(#article.text)
end
But i get an error:
uninitialized constant ArticlesController::Asciidoctor
Whats the right way to user asciidoctor-gem with rails?
Please remember to restart your server after changing something outside the Rails auto-reloading path (i.e. app/* and config/routes.rb).
Since the documentation looks exactly like your example
puts Asciidoctor.render '*This* is http://asciidoc.org[AsciiDoc]!'
I'd guess, you simply forgot to restart the server.

uninitialized constant - loading class issue?

So, I got mailer app/mailers/dynamic_mailer.rb and model app/models/email_message/outgoing.rb. There is method:
class EmailMessage::Outgoing < EmailMessage
...
def deliver_mail
l = ::DynamicMailer.email_message(self).deliver!
Rails.logger.info "SEND MAIL: #{l.inspect}"
update_attribute(:received_at, Time.now)
end
Locally (developement env) everything works fine. The problem occurs when I'm deploying app to server (staging env) and trying to send email form there. Delayed job prints:
[Worker(host:rdev pid:2279)] EmailMessage::Outgoing#send_email!
failed with NameError: uninitialized constant
EmailMessage::Outgoing::DynamicMailer - 11 failed attempts
It looks like a problem with loading classes on server. Removing double colons before class name fails.
Any help will be greatly appreciated.
Try to specify file with DynamicMailer obviously in file with your model like this require 'app/mailers/dynamic_mailer.rb'. Probably it can help to find necessary class.
Also I've noticed that in error message is mentioned send_email! method but you posted here def deliver_mail method. Whether I don't understand something or you're looking in wrong place.
I just forgot to restart delayed job daemon.
You can do it with capistrano, by adding gem 'daemons' to your Gemfile and updating receipes like that: http://cmar.me/2011/02/21/delayed_job-with-rails-3-and-capistrano/

Why am I getting a "uninitialized constant Feed::Feedzirra" error?

I'm developing a ruby on rails -v 3.1.3 app that needs to pull a rss feed down. I've successfully installed feedzirra by adding it to my gemfile and running bundle install.
In my controller for the page that will display the rss feed I have
#feed = Feed.new(blog_url_here)
and I have a class named Feed.rb in my models folder that contains this:
def initialize(endpoint)
atom = Feedzirra::Feed.fetch_and_parse endpoint
#atom = atom.is_a?(Feedzirra::Parser::Atom) ? atom : nil
end
When I load the page I get an "uninitialized constant Feed::Feedzirra" error. Anyone know why and how I can fix it?
Maybe it will help someone:
You should restart rails server after bundle install.

Resources