I am trying to create rails engine using the below link:
http://guides.rubyonrails.org/engines.html
I have received below errors
You have one or more invalid gemspecs that need to be fixed.
The gemspec at /home/shariq/Documents/plugin/blorgh/blorgh.gemspec is not valid. Please fix this gemspec.
The validation error was '"FIXME" or "TODO" is not a description'
I already tried bundle update and bundle install
Here is all myworking
log
shariq#SDEV-MACHINE:~/Documents/plugin$ ruby -v
ruby 2.3.1p112 (2016-04-26 revision 54768) [x86_64-linux]
shariq#SDEV-MACHINE:~/Documents/plugin$ rails -v
Rails 5.0.0.1
shariq#SDEV-MACHINE:~/Documents/plugin$ mysql --version
mysql Ver 14.14 Distrib 5.7.15, for Linux (x86_64) using EditLine wrapper
shariq#SDEV-MACHINE:~/Documents/plugin$ rails plugin new blorgh --mountable -d mysql
create
create README.md
create Rakefile
create blorgh.gemspec
create MIT-LICENSE
create .gitignore
create Gemfile
create app
create app/controllers/blorgh/application_controller.rb
create app/helpers/blorgh/application_helper.rb
create app/jobs/blorgh/application_job.rb
create app/mailers/blorgh/application_mailer.rb
create app/models/blorgh/application_record.rb
create app/views/layouts/blorgh/application.html.erb
create app/assets/images/blorgh
create app/assets/images/blorgh/.keep
create config/routes.rb
create lib/blorgh.rb
create lib/tasks/blorgh_tasks.rake
create lib/blorgh/version.rb
create lib/blorgh/engine.rb
create app/assets/config/blorgh_manifest.js
create app/assets/stylesheets/blorgh/application.css
create app/assets/javascripts/blorgh/application.js
create bin/rails
create test/test_helper.rb
create test/blorgh_test.rb
append Rakefile
create test/integration/navigation_test.rb
vendor_app test/dummy
run bundle install
You have one or more invalid gemspecs that need to be fixed.
The gemspec at /home/shariq/Documents/plugin/blorgh/blorgh.gemspec is not valid. Please fix this gemspec.
The validation error was '"FIXME" or "TODO" is not a description'
shariq#SDEV-MACHINE:~/Documents/plugin$
here is gemspec file:
##### log #######
$:.push File.expand_path("../lib", __FILE__)
require "blorgh/version"
Gem::Specification.new do |s|
s.name = "blorgh"
s.version = Blorgh::VERSION
s.authors = ["Shariq"]
s.email = ["gr8shariq#live.com"]
s.homepage = "TODO"
s.summary = "TODO: Summary of Blorgh."
s.description = "TODO: Description of Blorgh."
s.license = "MIT"
s.files = Dir["{app,config,db,lib}/**/*", "MIT-LICENSE", "Rakefile", "README.md"]
s.add_dependency "rails", "~> 5.0.0", ">= 5.0.0.1"
end
The error is self-explanatory. You have to replace the "TODO" strings in the gemspec with some "actual" descriptions.
There is an already closed issue #26474 in rails repository:
rails plugin new does not complete properly since bundler 1.12
Ruby on Rails team member vipulnsward said:
We don't bundle install now - fbd1e98
fbd1e98's commit message explains:
Do not run bundle install when generating a new plugin.
Since bundler 1.12.0, the gemspec is validated so the bundle install
command will fail just after the gem is created causing confusion to the
users. This change was a bug fix to correctly validate gemspecs.
Add an option -B to skip bundle install:
rails plugin new NAME -B
If you need to run the bundler, you can remove every occurrence of TODO and FIXME from your .gemspec file and then run bundle install.
I met the issue today. Here is what I did(git diff) make me survive.
## -9,15 +9,15 ## Gem::Specification.new do |spec|
spec.version = Blorgh::VERSION
spec.authors = ["Torvalds Du"]
spec.email = ["torvalds#ekohe.com"]
- spec.homepage = "TODO"
- spec.summary = "TODO: Summary of Blorgh."
- spec.description = "TODO: Description of Blorgh."
+ spec.homepage = ""
+ spec.summary = "Summary of Blorgh."
+ spec.description = "Description of Blorgh."
spec.license = "MIT"
# Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
# to allow pushing to a single host or delete this section to allow pushing to any host.
if spec.respond_to?(:metadata)
- spec.metadata["allowed_push_host"] = "TODO: Set to 'http://mygemserver.com'"
+ spec.metadata["allowed_push_host"] = "http://mygemserver.com"
else
raise "RubyGems 2.0 or newer is required to protect against " \
"public gem pushes."
therefore, you have to remove all the text TODO from gem_name.gemspec.
Good luck.
Put this instead.
Gem::Specification.new do |spec|
...
spec.homepage = "https://example.com"
spec.summary = "Summary of App."
spec.description = "Description of App."
spec.metadata["allowed_push_host"] = spec.homepage
spec.metadata["homepage_uri"] = spec.homepage
spec.metadata["source_code_uri"] = spec.homepage
spec.metadata["changelog_uri"] = spec.homepage
...
end
Related
I am trying to build a rails engine and I have some gems that I want to isolate and bundle only in the rails engine Gemfile. I put these gems in my Gemfile:
source 'https://rubygems.org'
gemspec
gem "pg", "0.15"
In my insurance.gemspec:
$:.push File.expand_path("../lib", __FILE__)
# Maintain your gem's version:
require "insurance/version"
# Describe your gem and declare its dependencies:
Gem::Specification.new do |spec|
spec.name = "insurance"
spec.version = Insurance::VERSION
spec.authors = ["Engine Sample"]
spec.email = ["engine#engine.com"]
spec.homepage = "https://github.com/engine/engine_plugin"
spec.summary = "Engine Sample."
spec.description = "Engine Sample."
spec.license = "MIT"
# Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
# to allow pushing to a single host or delete this section to allow pushing to any host.
if spec.respond_to?(:metadata)
spec.metadata["allowed_push_host"] = "TODO: Set to 'http://mygemserver.com'"
else
raise "RubyGems 2.0 or newer is required to protect against " \
"public gem pushes."
end
spec.files = Dir["{app,config,db,lib}/**/*", "MIT-LICENSE", "Rakefile", "README.md"]
spec.add_dependency "rails", "~> 5.0.1"
spec.add_development_dependency "route_translator"
end
Then I go to my engine on terminal and run bundle install which generates a Gemfile.lock in my engine folder.
I then go to main application and add in main application Gemfile this:
gem 'insurance', path: '/home/Documents/Projects/insurance'
I also created some routes in my engine folder config/routes.rb
but when I run my application, I get this error
Gem::LoadError - pg is not part of the bundle. Add it to your Gemfile.:
Rails engines are actually gems, they are supposed to rely on parent app's Gemfile.lock and only specify dependencies in their gemspec.
If you want some gem to be a dependency of the engine - then add it to gemspec, and if you want to lock exact version - do so in dependency declaration (but in fact, it's better to specify a more loose version):
spec.add_dependency "pg", "0.15" # better use something like "~>0.15" here
I always dread creating a new project due to the amount of setup it sometimes requires. I have a number of Gems that I always use, some of which require additional configuration.
Now, I've done some research on the subject, and I can't seem to find anything about it, which, I think, is odd, since it would benefit the flow of starting a new Rails Project.
I suspect maybe that this has some broader Rails term that I haven't discovered yet.
So, is there a way to keep your favorite Gems (or any Gems) already installed and ready to go when you run the command:
rails new YourProject
Update
Rails Appliaction Templates was exactly what I was looking for.
I have no a favorite gem or something like that, but I have a template for the project creation process Rails Application Templates, railsrc.rb:
gem 'awesome_print', require: false
gem_group :development do
gem 'puma'
gem 'pry-rails', '~> 0.3.2'
gem 'zeus'
end
gem_group :test do
gem 'minitest-rails'
gem 'letter_opener'
gem 'ffaker', require: false
end
run "bundle install --path vendor/bundle"
#install minitest test_helper
generate 'mini_test:install'
environment "config.generators do |g|\n g.test_framework :mini_test, spec: true, fixture: true\n end"
# Add pride to minitest config
run "sed -i '' '4 s#^#require \"minitest/pride\"#' test/test_helper.rb"
#create postgres DB for postgress.app
#development and test
run "psql -c 'CREATE DATABASE #{app_path}_development;'"
run "psql -c 'CREATE DATABASE #{app_path}_test;'"
# add database yml
run "sed -i '' '4 s#^#require \"minitest/pride\"#' test/test_helper.rb"
#Add minitest features to Rake task
run %q^echo 'MiniTest::Rails::Testing.default_tasks << "features"' >> Rakefile^
#Fix README.md
run "rm README.rdoc"
run "touch README.md"
#Initialize local Git repository and Initial Commit
git :init
git add: "."
git commit: "-a -m 'Initial commit :pray:'"
Then I run rails new my_awesome_app -m ~/railsrc.rb, it build a brand new project with my requirements from railsrc.rb
Bundler
Bundler is the project you're looking for.
I'm not even sure how you can use Rails without it.
Once you have a Gemfile you like, it should take no more than 30 seconds to use the exact same gems for a new Rails project.
Alternatives
Your question isn't clear, and you don't provide any example so it's hard to know what you're looking for. If you have a common base for all your Rails projects, you might consider Engines, git branches or even whole virtual machines.
I'm trying to compile my first gem and push it to rubygems.org. It keeps throwing an error saying I can't push to https://rubygems.org:
gem build simplesms.gemspec
WARNING: licenses is empty, but is recommended. Use a license identifier from
http://spdx.org/licenses or 'Nonstandard' for a nonstandard license.
WARNING: no homepage specified
WARNING: See http://guides.rubygems.org/specification-reference/ for help
Successfully built RubyGem
Name: simplesms
Version: 0.1.0
File: simplesms-0.1.0.gem
Toms-MacBook-Pro-2:simplesms t$ gem push simplesms-0.1.0.gem
Pushing gem to https://rubygems.org...
ERROR: "https://rubygems.org" is not allowed by the gemspec, which only allows "'http://rubygems.org'"
But in my spec:
# coding: utf-8
lib = File.expand_path('../lib', __FILE__)
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
require 'simplesms/version'
Gem::Specification.new do |spec|
spec.name = "simplesms"
spec.version = Simplesms::VERSION
spec.authors = ["Tom"]
spec.email = ["tom#example.com"]
spec.summary = %q{Easily add sms to your project by integrating the Simple SMS Heroku Addon into your app.}
spec.homepage = ""
# Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
# to allow pushing to a single host or delete this section to allow pushing to any host.
if spec.respond_to?(:metadata)
spec.metadata['allowed_push_host'] = "'http://rubygems.org'"
else
raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
end
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
spec.bindir = "exe"
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
spec.require_paths = ["lib"]
spec.add_development_dependency "bundler", "~> 1.12"
spec.add_development_dependency "rake", "~> 10.0"
end
In the gemfile:
source 'http://rubygems.org'
# Specify your gem's dependencies in simplesms.gemspec
gemspec
Just for kicks I also tried setting them to 'https://rubygems.org', however it still throws the same error.
Any idea what I need to do to get this to push to rubygems.org? I already signed in with my email/password and confirmed the credentials are in ~/.gem/credentials
This line:
spec.metadata['allowed_push_host'] = "'http://rubygems.org'"
You're setting allowed_push_host to 'http://rubygems.org'. It should just be http://rubygems.org (without the single quotes). Change it to:
spec.metadata['allowed_push_host'] = "http://rubygems.org"
It should be safe (and preferred) to allow https://rubygems.org instead, too.
I'm creating a Rails web application which uses a shared library of models (as a Rails Engine), stored in a subrepository (Git subtree.) This shared library contains dependencies on other Ruby gems (in my case, HTTParty and Dalli), of which I want to be automatically referenced by the parent project that includes this shared library.
However, my gem's dependencies don't appear to be resolving in the parent project, and when I start my web application, it has missing references to those gem dependencies in the shared library. (i.e. NameError: uninitialized constant ApiClient::HTTParty) If I explicitly add those references to my web app's Gemfile (as in uncomment the Gemfile lines below), everything works fine.
How do I get these dependencies to 'chain', and have the parent project automatically resolve these references?
Here's what my project looks like:
[MyRailsApp]
-- ...
-- [app]
-- [config]
-- [lib]
-- [MyLib]
-- ...
-- [app]
-- [config]
-- [lib]
-- [MyLib]
-- version.rb
-- engine.rb
-- MyLib.gemspec
-- Gemfile
-- Gemfile
MyRailsApp/Gemfile:
source 'https://rubygems.org'
gem 'activesupport', '3.2.13', :require => 'active_support'
gem 'actionpack', '3.2.13', :require => 'action_pack'
gem 'actionmailer', '3.2.13', :require => 'action_mailer'
gem 'railties', '3.2.13', :require => 'rails'
...
# gem 'dalli'
# gem 'httparty'
gem 'MyLib', :path => 'lib/MyLib'
MyLib/MyLib.gemspec:
$:.push File.expand_path("../lib", __FILE__)
# Maintain your gem's version:
require "mylib/version"
# Describe your gem and declare its dependencies:
Gem::Specification.new do |s|
s.name = "MyLib"
s.version = MyLib::VERSION
s.authors = ["David"]
s.email = ["ops#myemail.com"]
s.homepage = "http://www.mysite.com"
s.summary = "Shared Library"
s.description = "Shared Library"
s.files = Dir["{app,config,db,lib}/**/*"] + ["MIT-LICENSE", "Rakefile", "README.rdoc"]
s.add_dependency "rails", "~> 3.2.13"
s.add_dependency "dalli", ">= 2.6.4"
s.add_dependency "httparty", ">= 0.11.0"
end
Figured it out. I had the wrong line of thinking... I thought Gemspecs, used for installing gem dependencies (which was working just fine), would also be used by Rails to determine what dependencies need to be loaded into memory when the application starts. This is not the case, at least, not when using Rails engines.
For the average gem, it appears that a typical Rails web app has a line in the boot.rb file which loads all gems and dependencies in the application Gemfile. However, this autoloading does not appear to extend to Rails engines listed in the Gemfile. In this case, you must load your dependencies into application memory manually, by finding the engine.rb file (in your Rails engine) and adding require 'yourgem' at the beginning of the file. This will load the dependency when the engine loads.
A friend found and linked me this relevant question/answer, if this explanation isn't sufficient:
https://stackoverflow.com/a/5850503
If you want rubygems to understand your dependencies, package each of them with a proper .gemspec file. You don't have to publish your gem, it can be private and referenced via a git:// type URL.
The thing is, generally your .gemspec needs to be at the root level. You can't bury it in your project as Rubygems does not go out of its way to look for these.
In your use case, MyLib should be a separate thing.
After having successfully installed and used the SDK on another computer for a project,
I'm struggling to make it works on another station, getting the following error :
[!] Unable to find a specification for `Facebook-iOS-SDK`.
The version of the SDK is v3.5.1.
With the following rakefile :
# -*- coding: utf-8 -*-
$:.unshift("/Library/RubyMotion/lib")
require 'motion/project'
require 'bundler'
require 'motion-cocoapods'
Bundler.require
Motion::Project::App.setup do |app|
app.name = 'FacebookApp'
app.frameworks = ["UIKit", "Foundation", 'AdSupport', 'Accounts', 'Social']
app.weak_frameworks += %w{ AdSupport Accounts Social }
app.pods do
pod 'Facebook-iOS-SDK'
end
app.device_family = :iphone
app.interface_orientations = [:portrait]
app.info_plist['FacebookAppID'] = 'xxx'
app.info_plist['URL types'] = { 'URL Schemes' => 'fb://profile/xxx'}
app.identifier = 'xxx'
end
And the following Gemfile :
# A sample Gemfile
source "https://rubygems.org"
gem "motion-cocoapods", "1.3.0.rc1"
gem "cocoapods"
gem 'bubble-wrap'
Would there be something that is to add (environments paths, another sdk version to install… whatever) ?
$ pod install --force
solved it. Some cache problem or something obviously.
EDIT
Usually, those kind of problems are solved with a rake clean:all, and a reinstall of it all (bundle install && rake pod:install)
I had the same error and it turns out I had already pod install'd in that dir. This can be checked by simply typing pod with no args.
For the pod n00bz like me, you will need to pod init to generate the podfile (this step is not in the Getting Started docs I am following at the moment).
For me, I had moved my repository to a new computer, and had not yet run this:
bundle exec pod setup