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.
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
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
I'm trying to upgrade to rails 4 beta 1, but I've a bit of a problem.
This is, in short, how my application controller looks like.
class ApplicationController < ApplicationController
caches_action :method
end
caches_action is moved out to it's own gem in Rails 4, so including the gem should fix the problem.
gem "actionpack-action_caching", github: "rails/actionpack-action_caching"
But when I run my requests specs or visit the application in a browser I get this error.
app/controllers/application_controller.rb:3:in `<class:ApplicationController>': undefined method `caches_action' for ApplicationController:Class (NoMethodError)
Why is that?
Rails 4.0.0.beta1
Ruby 2.0.0
Rspec 2.13.1
As the caching is not a part of core anymore, you need to explicitly require it in top of every file you use it in:
require 'actionpack/action_caching'
The problem is in Rails 4, they have extracted cache part into separate gems
if you are getting error for action caching then you need to add below gem
gem 'actionpack-action_caching'
for page caching have to add
gem 'actionpack-page_caching'
I also played around then I figure out that, have not added gem to do the same.
hope that will works. Thank you.
Iam using rails as an API rails new AppName --api
I got it working by adding
include ActionController::Caching
in class ApplicationController < ActionController::API
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