Reputation: 4728
I wrote ruby code which pulls content from Google API. It works as a standalone example.rb
file. I need to add this to my RoR app. What is the standard way to do it? How should I call this code from the controller? Should I add this code in some model file, keep the code in /lib
folder, or put the code in /vendor/plugins
folder?
Upvotes: 0
Views: 86
Reputation: 14750
Either extract it out into a gem, or you could put it in lib
if you wanted.
If you take the second approach, here's an example. Say you have it in a module (Google)
#lib/google.rb
module Google
class Uploader
def initialize
...
end
def foo
...
end
end
...
end
in your controller
require 'google'
class MyController < ApplicationController
def new
uploader = Google::Uploader.new # do whatever here
uploader.foo
end
end
There are many ways to modify / use this module approach, the given code is only one possibility.
Upvotes: 5