We've got a developer who gets errors with a gem while using zsh, but the rest of us would still like to use the gem. Is there a good solution for this?
From here, add the following code to the bottom of your gemfile.
gemfile_local = File.join(File.dirname(__FILE__), 'Gemfile.local')
if File.readable?(gemfile_local)
puts "Loading #{gemfile_local}..." if $DEBUG
instance_eval(File.read(gemfile_local))
end
Have each of the developers who want to use the problem gem to add it to their Gemfile.local. This is the most elegant solution I have found for using gems you don't want to commit to version control. Don't forget to add Gemfile.local to your .gitignore.
Related
I am trying to edit a specific gem:
https://github.com/rderoldan1/md_simple_editor
The issue is that the editor does not load without a page refresh first.
The issue can be checked here: https://github.com/rderoldan1/md_simple_editor/issues/9
I was able to fix this in my local by editing the file:
/usr/local/rvm/gems/ruby-2.3.4/gems/md_simple_editor-0.3.0/app/assets/javascripts/md_simple_editor.js.coffee
It is fixed by just editing the code as the other users are saying in the issue posted in the gem url above.
I cant find the right place to fix this in production, can someone point me in the right directory path?
Thanks in advance.
Don't do it that way. Fork the gem, make the changes in the gem code and make sure you write tests that prove your code works as expected. Then push the code to your forked repo on github.
Then make a pull request and support the open source community. In the mean time, you can use your version of the gem by edit your Gemfile like so:
gem 'md_simple_editor', github: 'lacostenycoder/md_simple_editor', branch: 'master'
Of course replace lacostenycoder with your github username.
I found an Amazon Gem that I want to use https://github.com/hakanensari/vacuum/.
I've only ever used gems with in depth tutorials or following a RailsCast. I'm looking for tips on using gems I find online. I'll explain the steps I'm doing, and hopefully someone can give me some ideas on what else I should be doing when using a new gem. Also, if you have a good tutorial or explanation on gems, that would be great too.
I started off examining the Gem on Github, I'll point out the things I took notice of. Let me know if there are things I'm missing I should notice.
Examining Gem on Github
Go to the examples and look at "examples/product_advertising/basic_lookup.rb"
Follow the required file, and checkout "examples/product_advertising/shared.rb"
Notice, I need to install "pry"
Notice, the examples expand on the "lib" folder
Check out "credentials.yml"
Notice a "#req" is instantiated as a new Vacuum object.
Then back in basic_lookup.rb, it looks like it's assigning the lookup value, then binding the response to some kind of "pry" view.
Next, I'll try implementing these examples in my own project. Here's where I'm not sure what to do as far, as files are concerned.
Attempt Implementing Example
Install vacuum gem
gem install vacuum
Install pry gem
gem install pry
Added "shared.rb" and "credentials.yml" to my "app/controllers" directory
Replaced the information in "credentials.yml" with my information
Attempt to copy the information from "basic_lookup.rb" into an existing controller
def amazon
require File.expand_path('../shared.rb', __FILE__)
res = #req.look_up '0816614024'
items = res.find 'Item'
binding.pry
end
Create a route
match '/test' => 'products#amazon'
Go to test page and receive the following error
undefined method 'look_up' for nil:NilClass
I would like to point out, at this point I haven't added the lib folder.
Questions
I like the credentials.yml is separated out, when I want to add this to my project, where should I save that file?
I like the shared.rb file, should I just put that in the controller folder?
Why is it referencing the "lib" folder in "shared.rb"? Do I need to copy that directory into my project?
I appreciate you sticking around and reading all of this. I'm still trying to get a handle on using a gems, so any help or tips are great. Really, I'm just trying to figure out, how do I find any gem and start using it appropriately.
Thanks for any help you can give me!
I like the shared.rb file, should I just put that in the controller folder?
Answer = yes, you just put that file in controller folder.
My setup: Rails 3.0.9, Ruby 1.9.2
I need to extend Active Merchant module to include my own code, I'm following the article here
http://blog.matthodan.com/how-to-add-support-for-paypal-website-payment
As per the article, I created paypal_recurring_payments.rb in /vendor/plugins/active_merchant/lib/active_merchant/billing/gateways/paypal/. Next I have to modify an Active Merchant gem file paypal.rb to add a line of code. The problem is that I can't deploy that code change to Heroku, so I need an alternate way of doing this. Any insights will be much appreciated.
Fork the gem on github
Make the appropriate change to your fork of the gem.
Reference your fork in the Gemfile using the :git option. See the docs for examples.
What ever happend to Rails.configuration.gems in Rails 3? I guess it has to do with Bundler. But how can I find all gems now?
Thanks
Yes it has to do with Bundler. In Rails 3 your application's gem manifest is in a file called Gemfile. Some good explanations on the changes and how to use them here, here, here and here.
UPDATE:
The bundle show CLI lists the gems in use by your application. But, programmatically you can get to the same thing as follows:
require 'bundler'
mygems = Bundler.load.specs.map { |spec| spec.name }
The spec object also contains other attributes of interest.
I'm having trouble getting rubygems to work in my Rails app. Specifically, I'm trying to use the json gem, documented here: http://flori.github.com/json/ I can successfully use JSON.parse() in IRB and script/console but not in my rails app.
I know it's some combination of config.gem 'json' in environment.rb and other things, but can't find a good explanation anywhere.
Can someone give me a concise list of what is required to use this gem OR point me towards comprehensive documentation of using gems in Rails? thanks!
config.gem is used for gem dependency in rails and it does nothing more than telling rails that a gem is needed, and helping the user install the appropriate gem, etc (more details here: http://ryandaigle.com/articles/2008/4/1/what-s-new-in-edge-rails-gem-dependencies)
however by installing a gem, it should be able to be used by the rails app automatically, if not, probably you can add require "json" into environment.rb or in an .rb files in the initializers folder?
Hope it helps =)
I solved it. There's decent documentation here: http://apidock.com/rails/Rails/Configuration/gem
Once you have used config.gem in environment.rb, you should not need to 'require' it later.
My problem was that I had not stopped and restarted the server! It worked in script/console because everything was getting reloaded every time.