Object not recognized in Rails controller - ruby-on-rails

I have this code in one of my controllers to get access to eventful.
eventful = Eventful::API.new('my_key_here')
However, I get the following error when I refresh my page
uninitialized constant LocationsController::Eventful
I installed the gem version 2.2.1 as directed through http://api.eventful.com/libs and my gemfile contains the line
gem 'eventfulapi', '2.2.1'
I am trying to recreate the example here: http://api.eventful.com/libs/ruby/doc/index.html
I can get it to work in a separate ruby script (e.x. running 'ruby a.rb' through command line) which leads me to thinking it's totally possible. I just can't get it to work in a controller to feed my application.

Try adding require 'eventful/api' at the top of the controller code.

Related

Ruby on Rails themoviedb-api gem isn't recognized by app

I'm crating movie/series focused app and I decided to use this gem: https://github.com/18Months/themoviedb-api#configuration. I added it to my Gemfile, then I used 'bundle install' command, the gem was successfully installed. So far I have done everything by the book. After installation I tried to check if it works properly so I insert this code into one of my controllers' index actions:
def index
#series = Series.all
Tmdb::Api.key("my_api_key")
Tmdb::Movie.detail(550, language: 'it')
end
Unfortunately my app doesn't seem to recognize Tmdb api, and I am getting the error:
uninitialized constant SeriesController::Tmdb

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.

Cannot find gem in controller

I'm sure this is an easy question but I'm having a hard time figuring out what to Google.
I'm trying to use the library ChunkyPNG.
I added it to my Gemfile and did a bundle install.
bundle list | grep "chunky"
* chunky_png (1.2.5)
So far so good.
I try using it in my controller:
image = ChunkyPNG::Canvas.from_data_url(params[:data]).to_image
(The docs for this method are available here)
It results in the following error:
NameError in MyController#create
uninitialized constant MyController::ChunkyPNG
Why is prepending the controller namespace? I imagine that's what is causing the error.
Otherwise, it means that ChunkyPNG is not install (and it clearly is).
Am I not able to use this gem upfront without writing some sort of rails plugin to wrap around it?
Thanks
EDIT:
Question has been answered, see #apneadiving's comment
In your controller, or somewhere else in the app do:
require 'chunky_png'

My rails 3 engine's controller is only found by rails every second page refresh, otherwise returns LoadError

i'm developing a rails 3 engine but really having troubles getting the
controller to load every time.
every second time I visit the page I get;
LoadError in Webedit/public filesController#index
Expected /home/anko/.rvm/gems/ruby-1.9.2-p136/bundler/gems/webedit-3e02394235c3/app/controllers/public_files_controller.rb
to define PublicFilesController
to reproduce (assuming bash, ruby 1.9.2 and rails 3);
rails new webedit-test
cd webedit-test
echo "gem 'webedit', :git => 'https://github.com/ankopainting/webedit.git', :tag => 'v0.0.3'" >> Gemfile
bundle install
rails server
then goto http://localhost:3000/public
it will either say "hi" or an error.. refresh to see it change to the
opposite behaviour.
any help would be greatly appreciated.. I've spent some time in ruby
debugger but need to understand a lot about how rails works to get a
meaningful result.
I used the source code you provided and added a directory under controllers. Seems to work fine now. Since you have the controller inside a module, you need to create this directory structure:
app/controllers/webedit/public_files_controller.rb
Not exactly sure why it was loading every other time, though.

Debugging/Breakpoint-ing the Rails Core with Ruby-Debug?

How do I debug the rails gems? I've just found the beauty of ruby-debug and am real excited, but I want to step through the routing code in action_controller, but the debugger isn't set up at this time, it seems like it's just skipping over my "debugger" calls in action_controller/routing/route_set.rb for example.
What am I missing?
I just tested this with Rails 2.3.4. I added a 'debugger' line to the call method in vendor/rails/actionpack/lib/action_controller/routing/route_set.rb, ran 'rdebug script/server', browsed to a page, and it stopped at the correct line.
You can also use a class/method breakpoint; you'll need to step through the first few lines of the app until you're past the require 'action_controller' line, and then enter: b ActionController::Routing::RouteSet.call.
Or you can try setting a breakpoint based on the file name and line number.

Resources