My Rails 4.2 app fails to load some GitHub hosted gem (installed via bundler v1.8.2). I am using rvm 1.26.10 (master)
In my Gemfile,
gem 'simple_form', '~> 3.1.0'
gem 'actionform', :github => 'rails/actionform'
Bundler install them in different location:
$ bundle show simple_form
/Users/me/.rvm/gems/ruby-2.1.5#my_app/gems/simple_form-3.1.0
$ bundle show actionform
/Users/me/.rvm/gems/ruby-2.1.5#my_app/bundler/gems/actionform-4a858fecf4c2
Rails never load the actionform gem.
After inserting the line //= require action_form to my app/assets/javascript/application.js file, this error comes
Sprockets::FileNotFound at / couldn't find file 'action_form'
However, the action_form.js file exists in the gem file.
Moreover, when i try to reproduce the readme example, i got this error
NameError at /conferences/new uninitialized constant ActionForm
require 'bundler/setup' is in boot.rb
Any advise about this issue?
Thanks!
The problem is a mismatch between the gem name and the file inside the gem. Because the gem is named 'actionform', Bundler will try to require 'actionform', however the file is actually called action_form.
You can tell Bundler the right file name with this syntax:
gem 'actionform', :github => 'rails/actionform', :require => 'action_form'
Note that it is normal for gems from git sources to be installed into a different location than gems installed from gem servers. It has nothing to do with this problem.
Related
I'm new to RoR and I keep getting this error when trying to install Amazon gem aws-3:
Could not find gem 'aws-3' in any of the gem sources listed in your Gemfile or available on this machine.
I'm using Rails 5.
The gem per se appears to successfully be installed:
$ gem install aws-s3
Successfully installed aws-s3-0.6.3
Parsing documentation for aws-s3-0.6.3
Done installing documentation for aws-s3 after 1 seconds
1 gem installed
Added it to my Gemfile:
gem 'aws-3', :require => 'aws/s3'
On the top of the Gemfile I have listed:
source 'https://rubygems.org'
You misspelled aws-s3 as aws-3in the Gemfile. It should be
gem 'aws-s3', :require => 'aws/s3'
Note: There's no gem which goes by the name aws-3. That is why you were getting the error.
As told by #Arun Kumar,
you need to add aws-s3 gem in your gemfile.Here is the github
I'm making a simple task where I need to parse an XML Http response, all the http is working fine, and I have my xml string....
I'm trying to use the xml-simple gem.
I've gem install xml-simple
I've also added gem 'xml-simple' to the gemfile
Ran bundle install with success
but when I try to require 'xml-simple' in my rake task it fails saying no such file to load -- xml-simple...
What am I missing???
Bundler tries to load the gem by using the gem name as the require path (i.e. require 'xml-simple'). But in the case of the xml-simple gem, the path is xmlsimple, not xml-simple.
So in your Gemfile, use this instead:
gem 'xml-simple', :require => 'xmlsimple'
Gems sometimes have a different require path than the gem name, try either:
gem 'xml-simple', :require => 'xml/simple'
or
gem 'xml-simple', :require => 'xmlsimple'
or whatever the correct require path is to specify
I just made my first setup of RoR, and creating a new application works fine. But when I want to run the rails server I get the following error:
C:/Ruby192/lib/ruby/gems/1.9.1/gems/delayed_job-2.1.3/lib/delayed/yaml_ext.rb:30:in 'remove_method': method 'to_yaml' not defined in Class (NameError)
I ran the "bundle install" in the app directory and installed all the necessary files (with some problems however, but I excluded the gems with problems in the gemfile) and the last bundle install said that I have successfully installed all the needed packs.
I'm lost and I can't find a similar error on the internet. Can you help me?
EDIT: I forgot to mention that I'm not having a problem with a new application. It's running an existing one (that I didn't build, but works fine for others) that the error is related to. Here's the gemfile for that app:
source 'http://rubygems.org'
gem 'rails', '3.0.3'
gem 'mysql'
gem "haml", ">= 3.0.0"
gem "haml-rails"
gem 'simple_form'
gem 'delayed_job'
#gem 'auto_crawlers'
gem 'will_paginate', '~> 3.0.beta'
group :test do
gem 'factory_girl_rails'
gem 'mocha'
end
group :development do
#gem "nifty-generators", "0.4.3", :git => "git://github.com/JonasNielsen/nifty-generators.git"
gem 'fastercsv'
end
gem "mocha", :group => :test
Do you think the error is because I left out the two gems with "#" ? Those were causing problems at first, and I don't think I need them to test some minor changes in the app (some views that I have to modify)
The issue is being described, and supposedly fixed here: https://github.com/collectiveidea/delayed_job/issuesearch?state=open&q=yaml#issue/194
Try this from the command line: irb -rubygems -r delayed_job and then from your bundled directory bundle-exec irb -rubygems -r delayed_job which will show if there is a difference between your system gems and your bundled setup - you might see an error in one or both attempts to run IRB.
If there is an error using bundle-exec but not with your system gems then it's a bundler issue. If not, are you sure the app is designed to function under Ruby 1.9? It looks like to_yaml isn't available at the point DJ is required, which implies it probably needs a require "yaml" somewhere.
Can someone tell me what I am doing wrong? I am trying to push a simple rails app to Heroku that uses MongoDB. My Gemfile contains the following line:
gem "mongo"
When pushing the app to Heroku it error's out with: no such file to load -- mongo
-----> Heroku receiving push
-----> Rails app detected
-----> Detected Rails is not set to serve static_assets
Installing rails3_serve_static_assets... done
-----> Gemfile detected, running Bundler version 1.0.3
Unresolved dependencies detected; Installing...
/usr/ruby1.8.7/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `gem_original_require': no such file to load -- mongo (LoadError)
Here is my whole gemfile:
require 'rubygems'
require 'mongo'
source 'http://gemcutter.org'
gem "rails", "3.0.0"
#gem 'rails', :git => 'http://github.com/rails/rails.git'
gem "mongo_mapper"
gem 'mongoid', '2.0.0.beta.20'
gem 'devise', :git => 'git://github.com/plataformatec/devise.git'
gem 'heroku', '1.13.7'
# Bundle edge Rails instead:
# gem 'rails', :git => 'git://github.com/rails/rails.git'
You dont need either of these lines in your Gemfile:
require 'rubygems'
require 'mongo'
Neither of those are required for bundler to update or install your gems.
Also, is there a reason why you're installing both mongoid and mongo_mapper?
Perhaps another approach that you can use, is to use something like https://mongolab.com, connect you application with the database on the cloud, and then make the deployment (only the rails application).I've been using MongoLabs for a while, and works pretty good, you can check your collections directly from there (you don't need to use the JS shell). This is just a suggestion, to make the deployment easier :)
I wrote a plugin that requires a gem as a dependency.
Where do I have to define this dependency?
I have tried to create a Gemfile in vendor/plugins/my_plugin/, but bundle install doesn‛t find this file.
Ok. I have solved.
1) Create a Gemfile in vendor/plugins/my_plugin like:
# Gemfile
source "http://rubygems.org"
gemspec
2) Create a gemspec file. In the folder vendor/plugins run this command:
bundle gem my_plugin
(Note this command ask you for overwrite some files. Check the files before answer: Y)
3) Open gemspec file in vendor/plugins/my_plugin/ and add before the keyword end:
s.add_dependency('will_paginate', '~> 3.0.pre2')
(In this example I have used will_paginate how required dipendency of my_plugin)
4) Now go in your rails app and edit Gemfile, add:
gem 'my_plugin', :path=>'vendor/plugins/my_plugin'
The path specified supposed that your plugin is already in vendor/plugins folder of your rails app.
Of course when deploy rails app you don't need anymore to specify :path argument.
5) Now in rails app root do:
bundle install
And dependency of my_plugin (will_paginate in this case) is installed.
Thank to Sinetris for initial input.
Create a Gemfile in your vendor/plugins/my_plugin/ like:
# Gemfile
source "http://rubygems.org"
gemspec
gem "your-dependency-gem-name"
note the gemspec directive.
Take a look at Using Bundler with Rubygem gemspecs for more information.
Sebtm's own answer is quite good, but it still didn't work as Tiago and orangechicken described. I had to add
require 'your-dependency-gem-name'
on top of lib/my_plugin.rb right before the engine of my_plugin is loaded.
See http://guides.rubyonrails.org/engines.html#other-gem-dependencies
Gemfile in the application folder.
# Bundle the extra gems:
# gem 'bj'
# gem 'nokogiri'
# gem 'sqlite3-ruby', :require => 'sqlite3'
# gem 'aws-s3', :require => 'aws/s3
Reference for myself. If you're making a plugin that should work with Rails as a RailTie, use rails plugin my_plugin to create the gem instead of bundle gem my_plugin. It saves you (me) a lot of trouble.
Edit: When do you need the gem to work as a RailTie? Whenever you want to add rails generator, rake tasks or add your code to a Rails app (Called Rails Engine).
/Edit
$ rails plugin new my_plugin
then you add dependencies
Gem::Specification.new do |s|
#...
s.add_dependency "rails"
s.add_runtime_dependency "heroku"
s.add_development_dependency "sqlite3"
end
to include it in your rails app, use path: as described by #Sebtm
or release it to rubygems.
$ gem build my_plugin.gemspec
$ gem push my_plugin-0.7.0.gem #replace version number
#in Gemfile, as always
gem 'my_plugin'
or tag it on github. (use their release UI) and depend on it using
gem 'my_plugin', github: 'accountname/my_plugin', tag: 'v0.7.0'