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 👍
Related
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)
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
tl;dr
I'm trying to break out a part of a larger application as a mountable engine. The engine will exist in different flavors, each contained in their own gem. I can't get the gem name be different from the engine constant name.
Details
The extracted part contains logic for registration, authentication and session handling. The application is used by clients in different parts of the world with different requirements and regulations regarding the end customers using the product. This prompted us to create separate modules for these needs for each regulatory region. They currently live in the lib directory and the different implementations are loaded depending on config.
The goal with the engines is that you mount the appropriate engine and the routes file routes all the concerned calls to the engine.
Since we have several such registration modules, and more to come, we need to maintain several gems for the variants. I'm trying to make it so that the gems have different names (auth_A, auth_B, etc) but the contained engine has the same contant name, Auth::Engine.
That way we can include the correct gem in the Gemfile and the rest will just work since the endpoint it should rout to is always the same regardless of what version is running.
Problem
The problem I run in to is that I can't seam to get the gem to have one name and the engine constant another...
If I generate a new engine names auth it works fine to mount it in the main app. If I then change the gem name and containing folder to auth_a and update the host apps Gemfile it stops working, I can bundle fine but when I try to start the host app it fails when it ties to mount the engine, complaining that Auth::Engine is an undefined constant.
My, slightly redacted, gemspec looks like this:
$:.push File.expand_path("../lib", __FILE__)
# Maintain your gem's version:
require "auth/version"
# Describe your gem and declare its dependencies:
Gem::Specification.new do |s|
s.name = "auth_a"
s.version = Auth::VERSION
s.authors = ["Jonas Schubert Erlandsson"]
s.email = ["jonas.schubert.erlandsson#xxxxxx.com"]
s.homepage = "http://some.page.on/the/internet.html"
s.summary = "Authentication module for A"
s.description = "This engine, when mounted in Host app, handles registration, account update, login and logout of users."
s.files = Dir["{app,config,db,lib}/**/*"] + ["MIT-LICENSE", "Rakefile", "README.rdoc"]
s.test_files = Dir["test/**/*"]
s.add_dependency "rails", "~> 3.2.13"
end
The only thing I have changed from the generated scaffold is s.name = "auth_a". The relevant line from the host apps Gemfile: gem 'auth_a', path: "../auth_a"...
I have looked through the entire source tree trying to find where it infers a name from the gem name but I can't see it. I don't know what I'm missing and the gem spec docs weren't much help for this either ... I didn't think that the gem name was bound to the constant names of the gem, but maybe I'm wrong? Can you override it? Or am I missing something else?
The answer to this was to simply add this to the line in the host apps Gemfile: gem 'auth_a', path: "../auth_a", require: 'auth'.
So it looks like it defaults to requiring, that is auto loading, a constant based on the gem name, but the require call tells it what to require instead.
Hope it helps someone else as well :)
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!
After authenticating with simplegeo, I am simply trying to perform this:
SimpleGeo::Client.get_context(37.772445,-122.405913)
Turn the result into #variable and display the #variable on my "view" page.
Any suggestions? Thanks!
I'm working on a gem right now called SimpleGeo-Rails. It should make the whole process of working with the SimpleGeo Places a lot more rails-like. Just add the following to your Gemfile and then checkout the readme.
gem 'simplegeo-rails', :git => 'https://github.com/mgadda/simplegeo-rails.git'