0

I'm trying to use this gem barometer and in the document it says that it can be used right out of the box with using require 'barometer'

I've always used gems and put them in the gemfile, but I think this is different...

Do I just download this entire repo, and copy all the files in the lib folder into my vendor folder? or maybe public folder?

Where would you typically put these files? And where would you include the require? Should this be in the application controller? Or maybe in the helper? Sorry for this really noob question.

I know in my local environment, I can just type in gem install barometer in my console, and not have to put in a require, but I don't think this will work in heroku, or production environment.

hellomello
  • 8,219
  • 39
  • 151
  • 297
  • 2
    put it in Gemfile. "require" might not be necessary at all (they often include that in doco in case you are using plain ruby)... if it doesn't Just Work, than add your require to your application.rb (not your controller), in `config/application.rb` – Taryn East Jul 29 '15 at 06:27
  • Heroku bundle-installs the gems based on the Gemfile. You can review the Heroku build log in the console (after you have run git push). – Rots Jul 29 '15 at 06:43
  • @TarynEast if not in controller, but Gareth, mentioned it can be? – hellomello Jul 29 '15 at 14:03
  • Ye s"it can"... but generally that kind of thing clutters up your controller/model etc. Generally requires go all in the one place. Often you don't even need them with a gem (you just put it in your Gemfile... and Gemfile requires it for you see: http://stackoverflow.com/questions/4800721/bundler-what-does-require-false-in-a-gemfile-mean) – Taryn East Jul 30 '15 at 00:36

1 Answers1

2

I've always used gems and put them in the gemfile, but I think this is different...

No, this is no different. Barometer is a Rubygem and putting it in your Gemfile is exactly the way to use it.

As with every library, your require should go in whichever file uses the code, for example the same file that the Barometer.new call is. You don't always need the require line depending on your Ruby environment, but it's always a good idea to get used to it

Gareth
  • 133,157
  • 36
  • 148
  • 157
  • But would I put it in a view.html.erb file? Or would it be better if I call it through the `model.rb`? Or it doesn't matter? Just as long as wherever the `Barometer.new` would be called would be okay? Just trying to figure out best practice purposes – hellomello Jul 29 '15 at 06:41
  • You probably don't want to doing anything that makes network calls in your views. If the barometer code relates to a specific model then you should probably put the code in there, otherwise it should be in your controller - or if that comes to more than a few lines of code, in another module which is *called* by your controller – Gareth Jul 29 '15 at 07:00
  • Cool, makes sense. Thanks for your help! – hellomello Jul 29 '15 at 07:01