I need to make changed to the Twitter gem, so I cloned it to a local folder, then changed my bundle file like so:
gem 'twitter', :path => '~/code/twitter-ruby'
I added a new method, and ran a test that simply calls the method, to start off with. But I get an error of undefined method. In other words, it hasn't detected my changes. I tried commenting out a whole file, ran my other tests and those all worked, as though the file were still there.
In my project I'm still importing as require 'twitter'.
I've tried running bundle update twitter, I've tried removing it from the bundle, I've tried increasing the version number (which it does detect, and updates to the most recent version), I've tried committing my changes to GIT. Nothing seems to work - I just keep getting the same undefined method error. Any ideas?
EDIT: my Gemfile.lock:
PATH
remote: /Users/Andrew/code/twitter
specs:
twitter (5.15.0)
GEM
remote: https://rubygems.org/
specs:
PLATFORMS
ruby
DEPENDENCIES
twitter!
BUNDLED WITH
1.12.4
My issue was that I was using bundle to install the gems, but I wasn't using bundle exec to run my application. It became clear after running the uninstall suggestion and the require my_lib line starting to fail inside irb. bundle exec irb allowed it to work using the gem path defined in the Gemfile.
try this out:
First uninstall the twitter gem, by doing gem uninstall twitter, then do bundle install
Try giving the branch name too.
gem 'twitter', path: <absolute-path-to-your-local-twitter-repo>, branch: <branch-name>
EDIT
e.g. path as "/Users/me/path/to/repo"
And run
bundle update twitter
Then restart server, if running as a web application.
Related
I'm trying to extract a couple of tasks into a gem, but cannot get the code to load in my Capfile. The code is at: https://github.com/floydj/capistrano-mysql_tables.
In my Gemfile:
gem "capistrano-mysql_tables", github: "floydj/capistrano-mysql_tables"
In my Capfile:
require "capistrano/mysql_tables"
After bundle install, it seems to be good, but running cap -T results in:
(Backtrace restricted to imported tasks)
cap aborted!
LoadError: cannot load such file -- capistrano/mysql_tables
What is wrong with the code in the gem? I've looked at other Capistrano plugins and have tried to imitate them, but it always gives this error and I've run out of things to try. It appears to be some kind of path problem, maybe. Here's what I see with gem contents:
$ bundle exec gem contents capistrano-mysql_tables
/Users/username/.gem/ruby/3.0.4/bundler/gems/capistrano-mysql_tables-d1b60186a06b/Gemfile
/Users/username/.gem/ruby/3.0.4/bundler/gems/capistrano-mysql_tables-d1b60186a06b/Gemfile.lock
/Users/username/.gem/ruby/3.0.4/bundler/gems/capistrano-mysql_tables-d1b60186a06b/LICENSE.txt
/Users/username/.gem/ruby/3.0.4/bundler/gems/capistrano-mysql_tables-d1b60186a06b/README.md
/Users/username/.gem/ruby/3.0.4/bundler/gems/capistrano-mysql_tables-d1b60186a06b/Rakefile
/Users/username/.gem/ruby/3.0.4/bundler/gems/capistrano-mysql_tables-d1b60186a06b/bin/console
/Users/username/.gem/ruby/3.0.4/bundler/gems/capistrano-mysql_tables-d1b60186a06b/bin/setup
/Users/username/.gem/ruby/3.0.4/bundler/gems/capistrano-mysql_tables-d1b60186a06b/capistrano-mysql_tables.gemspec
/Users/username/.gem/ruby/3.0.4/bundler/gems/capistrano-mysql_tables-d1b60186a06b/lib/capistrano-mysql_tables.rb
/Users/username/.gem/ruby/3.0.4/bundler/gems/capistrano-mysql_tables-d1b60186a06b/lib/capistrano/mysql_tables.rb
/Users/username/.gem/ruby/3.0.4/bundler/gems/capistrano-mysql_tables-d1b60186a06b/lib/capistrano/mysql_tables/version.rb
/Users/username/.gem/ruby/3.0.4/bundler/gems/capistrano-mysql_tables-d1b60186a06b/lib/capistrano/tasks/mysql_tables.rake
/Users/username/.gem/ruby/3.0.4/bundler/gems/capistrano-mysql_tables-d1b60186a06b/test/capistrano/mysql_tables_test.rb
/Users/username/.gem/ruby/3.0.4/bundler/gems/capistrano-mysql_tables-d1b60186a06b/test/test_helper.rb
Update:
After fixing the mistake found by #Alex, it still didn't work. However, I decided to push the gem to RubyGems, and then install via Gemfile in the standard way:
gem "capistrano-mysql_tables"
And after the standard install command, it works fine. But why does it work now? I suppose it has something to do with paths, the contents now list the following:
/Users/username/.gem/ruby/3.0.4/gems/capistrano-mysql_tables-0.0.2/Gemfile
/Users/username/.gem/ruby/3.0.4/gems/capistrano-mysql_tables-0.0.2/Gemfile.lock
/Users/username/.gem/ruby/3.0.4/gems/capistrano-mysql_tables-0.0.2/LICENSE.txt
/Users/username/.gem/ruby/3.0.4/gems/capistrano-mysql_tables-0.0.2/README.md
/Users/username/.gem/ruby/3.0.4/gems/capistrano-mysql_tables-0.0.2/Rakefile
/Users/username/.gem/ruby/3.0.4/gems/capistrano-mysql_tables-0.0.2/bin/console
/Users/username/.gem/ruby/3.0.4/gems/capistrano-mysql_tables-0.0.2/bin/setup
/Users/username/.gem/ruby/3.0.4/gems/capistrano-mysql_tables-0.0.2/capistrano-mysql_tables.gemspec
/Users/username/.gem/ruby/3.0.4/gems/capistrano-mysql_tables-0.0.2/lib/capistrano-mysql_tables.rb
/Users/username/.gem/ruby/3.0.4/gems/capistrano-mysql_tables-0.0.2/lib/capistrano/mysql_tables.rb
/Users/username/.gem/ruby/3.0.4/gems/capistrano-mysql_tables-0.0.2/lib/capistrano/mysql_tables/version.rb
/Users/username/.gem/ruby/3.0.4/gems/capistrano-mysql_tables-0.0.2/lib/capistrano/tasks/mysql_tables.rake
I'm glad I got it working, but would like to know why it failed before? Any ideas?
I have been having a problem with assert_template in rails. When running rails t it gives me an error message:
NoMethodError: assert_template has been extracted to a gem. To continue using it, add gem 'rails-controller-testing' to your Gemfile.
After adding gem 'rails-controller-testing' to the Gemfile and running bundle install everything worked great.
However, when using a different computer and using git pull to sync the repository it doesn't work. Instead it just shows the same error as above.
Always remember there's two Gemfile files. There's Gemfile, which you edit, and then there's Gemfile.lock. You add something to the Gemfile manually, you then run bundle install, which will lock the version. You edit the Gemfile directly, but the Gemfile.lock is a system managed file that you don't touch. Make sure you commit and push them both after adding a Gem :D
I am developing a gem meant to be used with Rails projects and want to try it out locally with another Rails app of mine.
I built the gem with bundle exec rake release which put a .gem file in the /pkg directory.
Then, in my Rails app, I added the following to my gemfile
gem 'mygem', '0.1.1', path: '/Users/me/projects/mygem/ruby/pkg'
I then ran bundle install which said it installed the gem. When I do this, it removes the gem from the path. IDK where it went.
When I start the Rails app, it's like the gem isn't included at all.
Interestingly, if I add a version that doesn't even exist, it still says bundle install works fine. (Example: gem 'mygem', '0.1.2345', path: '/Users/me/projects/mygem/ruby/pkg')
What am I supposed to do to try out my Gem locally with a Rails app?
This question is different from How can I specify a local gem in my Gemfile? because I explicitly tell bundle in my Gemfile to use the local gem, with the path given, and it still doesn't work. When I run bundle install, it says
Using mygem 0.1.1 from source at /Users/me/projects/mygem/pkg
So you'd think it works right, but it still doesn't.
Interestly, if I try it with a version number that doesn't exist, like mygem 1.2.3, it still runs bundle install successfully, which is really weird and seems like a bug:
Using mygem 1.2.3 (was 0.1.1) from source at /Users/me/projects/mygem/pkg
I prefer to use the following when working on a local gem side-by-side with a Rails project:
gem 'foo',
:git => '/path/to/local/git/repo',
:branch => 'my-fancy-feature-branch'
In our project, we ran
bundle package --all
one time, which according to documentation, remembers the "--all" option in subsequent calls. If I want to test a gem on my project by hardcoding it's path into the Gemfile such as:
gem 'blocks', :path => "/Users/hunterae/Projects/blocks",
anytime I run bundle install, all of the source code for this gem will be copied into my /vendor/cache directory. This means that if I make a change to the gem I am testing, I have to shut down my rails server and run bundle install again, whereas before "bundle package --all" was run, I used to be able to just stop and start my rails server.
My question is how do I get "bundle package" to once again only package gems and not try and cache :path gems? Where is the "--all" option remembered in bundler?
Look in .bundle/config in your project directory for a line that says BUNDLE_CACHE_ALL: true.
Delete that line to make it revert to packaging only standard gems.
In general, remembered options are stored in .bundle/config.
+1 to the answer form Tim Moore. Following is an addition to it.
You should avoid using :path in your Gemfile if possible and if working with a gem available on github. Since Bundler 1.9 you can use sth. like
bundle config local.name_of_gem /path/to/checked_out/repo
This will add an entry in ~/.bundle/config like
less ~/.bundle/config
---
BUNDLE_LOCAL__NAME_OF_GEM:
"/path/to/checked_out/repo/name_of_gem"
You can remove the config with the same command and including --delete like
bundle --delete config local.name_of_gem /path/to/checked_out/repo
This will avoid many problems and is easy to maintain.
I've forked a gem, and in trying to change it, decided to change the the gemfile from my git repository (which had been updating fine):
gem 'bootstrap-wysihtml5-rails', :git => 'git://github.com/Asherlc/bootstrap-wysihtml5-rails.git'
to the local directory (just the cloned git repository):
gem 'bootstrap-wysihtml5-rails', :path => '/Users/ashercohen/Documents/bootstrap-wysihtml5-rails'
Upon running either bundle update or bundle install, it shows the correct version number (updated since switching gem sources) in the readout. However, none of the files in the /vendor/assetspath seem to be getting updated in my Rails app. Is there some kind of caching thing I need to clear out?
I don't have a /vendor/cache file in my Rails app, and I'm confident that since the gem version is updating correctly in the bundler readout that the path is correct.
Is there some step I'm missing here?
Turns out Chrome was just aggressively caching the JS.