Uninitialized constant YoutubeIt in rails application - ruby-on-rails

I am making a rails(3.0.11) application using youtube_it api. My index action of videos controller contains the basic code of getting the client object:
#yt_client ||= YoutubeIt::Client.new(:username => 'my uname', :password => 'my pwd',:dev_key => 'my devkey')
I have installed the gem using gem install youtube_it, included it in the app's gem file gem 'youtube_it' and ran bundle install. But when i restart the server and go to the index page,
i get this Error
"uninitialized constant VideosController::YoutubeIt"
What am i doing wrong?

Try:
YouTubeIt
With a capital T
Hope that helps

I think you need to do
require 'youtube_it'
in either the application controller or in some lib or config file
Hope it helps

you have a typo, the correct sintaxis is
client = YouTubeIt::Client.new
and if you still have problem you can try this way
client = ::YouTubeIt::Client.new
cheers!

Related

Rails "Browser Gem" support

I'm new to Rails, I'm trying to get the "browser" gem working.
(https://github.com/fnando/browser)
I was hoping someone had some example code they code post. I installed the gem by putting gem "browser", require: "browser/browser" in my gemfile.
I ran gem install browser
So I don't really know how to use the gem to actually get the users browser info. I tried just doing this as a test in the view <%= browser.full_version %> but I get Template::Error (undefined local variable or method browser'
any example code on what to put in a view/modal/controller would be appreciated, thanks.
You need to instantiate the object. So you can do something like this:
def index
#browser = Browser.new(request.env["HTTP_USER_AGENT"])
end
Then you can call the object in your view:
Device: <%= #browser.device.name %><br>
Platform: <%= #browser.platform.name %><br>
Info: <%= #browser.to_s %><br>
PS. I tried using this gem but found useragent which seemed to better display the information I wanted.
You can simply install the gem and "call it" in your view.
For example:
<% if browser.device.mobile? || browser.platform.android? %>
To install this gem you need:
add gem declaration to Gemfile
run bundle install from the console
restart your development server
P.S. when you are starting to use any gem, you should carefully read gem's README first. In 95% cases they are documented good enough.

Uninitialized Constant GooglePlaces

I am currently using the google_places gem to try to access the places API. I am using the following code to get results:
class PlacesController < ApplicationController
def index
if params[:search]
#client = ::GooglePlaces::Client.new(Rails.application.secrets.places_api_key)
#places = #client.spots_by_query(params[:search])
end
end
end
I am running into an error of uninitialized constant GooglePlaces, which is replaced with PlacesController::GooglePlaces if I don't scope out. I believe this is a scoping issue, but nothing that I have tried fixes the issue. I am following the directions in the repo's readme and assuming that I don't have to include the source in the lib directory of my site. I can use the gem correctly from the rails console.
To use this API in rails application you need to use google_places gem.
add in gem file and run bundle install and restart the server once
gem 'google_places'
Next Create a project in google console and generate secret key .
https://code.google.com/apis/console
https://developers.google.com/places/documentation/
Finally restart the server
The docs said the API auth call should be:
#client = GooglePlaces::Client.new(Rails.application.secrets.places_api_key)

Where do I require the songkickr gem file?

I am attempting to use the songkickr gem in a rails app. I have installed the gem using the
gem install songkickr
The next step of the instruction is to:
require 'songkickr'
remote = Songkickr::Remote.new API_KEY
Where do I do this? In what file?
The github page for the gem is https://github.com/jrmehle/songkickr
and my github for this is on https://github.com/jeremybelcher/travel
Sorry for the beginner question, trying to lean al this. Any help is very much appreciated.
In your gemfile at your application root you need to add the line
gem 'songkickr'
Then run
bundle
There are several places where you can put ruby code in a Ruby on Rails app and you should just choose one of them, depending which makes the most sense for you application. For a start, how about you just try putting that code in one of your controllers?
In your Gemfile, add:
gem 'songkickr'
Then run the following command: bundle
At the top of the controller put:
require 'songkickr'
API_KEY = ""  # edit this line
Then in some action you can do this to test it out:
remote = Songkickr::Remote.new API_KEY
Later you might decide to make the "remote" object persist between requests and then you would need to do something more complicated.
Add require 'songkickr' to your application controller
Example:
class ApplicationController < ActionController::Base
protect_from_forgery
require 'songkickr'
end

Can't use Geocoder class in my controller

I have such trouble: I want to use ajax request to get user location, so I created action in my controller and rendering the result of Geocoder function in json. Here is code:
def find_location
location = Geocoder.coordinates(params[:location])
render :json => (location)
end
Locally it works great, on heroku it works too, but when I added this code to another project - it shows me this error
NameError in ConnectionsController#find_location
uninitialized constant ConnectionsController::Geocoder
It is strange, because this is working in console:
Geocoder.coordinates "Ukraine"
=> [48.379433, 31.16558]
I tried to include Geocoder::Model, but it doesn't work.
Can someone help me ?
Based on this issue you have to restart the whole production machine, not only your apache or nginx.
I actually had to open an issue because it doesn't work for me.
https://github.com/alexreisner/geocoder/issues/501
make sure your geocoder gem is not grouped inside :development, or :test inside the Gemfile
it should be outside the groups so that I could accessed in all the environments
Ex:
#Gemfile
group :development, :test do
#your gems
end
gem 'geocoder'
Do you use Docker for your backend code by any chance?
If you do so, then after you installed any gem, you need to stop the Rails container, build (or pull down from dockerhub if you use dockerhub) the new image, and start your containers again.
All is well 👍

Authlogic_OAuth fails with error "uninitialized constant UserSession::OAuth" in Rails 3

I've gotten my application to work (i.e. sign_in and sign_up) with Authlogic and I'm now trying to add support for OAuth through the Authlogic_OAuth gem. I've gotten all of the basics set up (I think) and I've added a "Login with Twitter" button to my landing page. The problem is that when I click the button I get this error:
uninitialized constant UserSession::OAuth
with the application trace:
app/models/user_session.rb:17:in `oauth_consumer'
app/controllers/user_sessions_controller.rb:23:in `create'
The function that is failing is in my user_session model:
# authlogic_oauth hacks
# Twitter example
def self.oauth_consumer
OAuth::Consumer.new("TOKEN", "SECRET",
{ :site => "http://twitter.com",
:authorize_url => "http://twitter.com/oauth/authenticate"})
end
I'm pretty new to rails and ruby so I don't quite understand where this namespace collision is coming from or how to solve it. Any help would be greatly appreciated.
OK, I figured it out. The problem is that OAuth::Consumer is not defined withing authlogic_oauth. It's actually defined in the oauth gem. so I updated my Gemfile to:
gem 'authlogic', '2.1.6'
# set up oauth capabilities. Note: :lib is replaced with :require in rails 3
gem 'authlogic-oauth', '1.0.8', :require => 'authlogic_oauth'
gem 'oauth', '0.4.4'
then run:
bundle install
and, don't forget to restart the rails server so that it reloads the gems from the Gemfile.
Try to change OAuth to ::OAuth. The colons mean that you want to access OAuth from outside your class. It was searching from your class.

Resources