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)
Related
I have installed the gem ruby-imagespec
The code looks like the following:
class TestController < ApplicationController
def ratio(fid)
file = File.new("#{Rails.public_path}/test/#{fid}.swf", "rb")
dimensions = ImageSpec.new(file)
return dimensions
end
helper_method :ratio
end
When I try to run this I get an error:
"uninitialized constant TestController::ImageSpec" on line 7 The
gem is listed in the gemfile and explicitly requiring it does not
work.
Where is the error? The gem is installed correctly and this code is just like the code from the gem's README
Looking at the ruby-imagespec repository, the file you need to require appears to be lib/image_spec.rb. Try require 'image_spec'.
ruby-imagespec is an unsupported gem, please try fastimage:
add gem 'fastimage' in your Gemfile
here the documentation https://github.com/sdsykes/fastimage
Cant figure out what I'm doing wrong.
Using hidemyass gem for proxy.
Using github example code.
class HomeController < ApplicationController
require 'hidemyass'
def index
HideMyAss.options[:max_concurrency] = 3
response = HideMyAss.get("www.google.com", timeout: 2)
end
end
Whey I try to use them in my rails controller, I get the Uninitialized constant error.
uninitialized constant HomeController::HideMyAss
Tried looking at the source to figure out with no luck. Maybe it's the problem with my code. Gemfile is good and tried looking at all the things causing the problem.
There is no need to write require 'hidemyass'
You just need to add gem 'hidemyass' to Gemfile and do bundle install. Check installation with gem list hidemyass command. I have successfully checked it and used github example. It works fine and smoothly.
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
I'm quite a beginner with Ruby On Rails and I need to implement client part of JSON API in order to use some external service.
I found a gem called jsonrpc and it looks perfect for me.
I've added it to my Gemfile as:
gem 'jsonrpc'
gem 'json'
and ran bundle
My code looks like this:
class SearchController < ApplicationController
def index
d = JsonRpcClient.new 'http://remote.bronni.ru/Dictionaries.ashx'
#countries = d.getCountries
end
But when I try to access it as http://localhost:3000/search, Rails says:
NameError in SearchesController#index
uninitialized constant SearchController::JsonRpcClient
I only have little experience with Rails so I'm asking you guys to help me out.
I really need to get this to work ASAP.
Thank you all in advance! I really appreciate your help!
UPDATE
I've tryed to get ActiveResource to work but I can't get how it build URL's. The remote service is not a Ruby XML app. (http://remote.bronni.ru/Dictionaries.ashx) And I need to use getCountries method so the URL should be http://remote.bronni.ru/Dictionaries.ashx/getCountries
I'm using flickr-fu gem within a rails application for flickr api integration. I'm following the sample code for setting up a web app shown below:
def flickr_create
flickr = Flickr.new(File.join(RAILS_ROOT, 'config', 'flickr.yml'))
redirect_to flickr.auth.url(:read)
end
def flickr_callback
flickr = Flickr.new(File.join(RAILS_ROOT, 'config', 'flickr.yml'))
flickr.auth.frob = params[:frob]
current_user.update_attribute :flickr_token, flickr.auth.token.token
flash[:notice] = "Succesfully authenticated with Flickr"
redirect_to :flickr_stream
end
I've registered flickr_callback as the callback method that flickr calls after the authorization process.
The problem is with the line in flickr_callback when I try and assign params[:frob] to flickr.auth.frob. I get the following error:
undefined method `frob=' for Flickr::Auth:0x24b3640
Even if I just require 'flickr_fu' from within console, create a new flickr instance, and attempt to assign to frob, I get the same error. I took a look at the gem source on github, and the setter frob= is set within the Flickr::Auth module, so I'm clueless as to where the error is. The API calls work successfully and the flickr object is initialized fine.
The issue is that the flickr-fu gem from gemcutter or github is at version 0.1.4, and the frob setter method wasn't implemented until subsequent version. Instead install the gem commonthread-flickr_fu v0.3.0 from github, and the frob is writeable.