I'm trying to add a gem depency in my engine but it does not work.
Here is my setting.
1- admin.gemspec
s.add_dependency "font-awesome-rails"
2- lib/admin.rb
require "admin/engine"
require "font-awesome-rails"
module Admin
end
But when i try to use the gem function in the engine, I got a NoMethodError
Has this changed in rails 4 ?
I'm assuming this is a mountable engine? It worked for me in a non-mountable one, but I'm running into the same issue and noticed (without resolution):
https://github.com/bokmann/font-awesome-rails/issues?q=engine
Looks like we're all rolling our own admin tools these days...
Related
I want to use Coveralls.io for my gem Headhunter that I'm developing at the moment. The doc says, I should simply add
gem 'coveralls', require: false
to the project, but as far as I know, this isn't the right way to load gems within another gem. Instead, stuff like that should happen in the .gemspec file. So I tried to add it like this:
s.add_development_dependency('coveralls', '>= 2.0')
But this doesn't work - it breaks my gem's whole functionality:
$ rake
/Users/josh/.rvm/rubies/ruby-2.0.0-p353/bin/ruby -S rspec ./spec/headhunter/css_hunter_spec.rb ./spec/headhunter/css_validator_spec.rb ./spec/headhunter/html_validator_spec.rb
/Users/josh/Documents/Work/MuheimWebdesign/headhunter/lib/headhunter/css_validator.rb:6:in `<class:CssValidator>': undefined method `full_gem_path' for nil:NilClass (NoMethodError)
This is the file that breaks:
require 'net/http'
require 'nokogiri/xml'
module Headhunter
class CssValidator
VALIDATOR_PATH = Gem.loaded_specs['headhunter'].full_gem_path + '/lib/css-validator/'
So Gem.loaded_specs['headhunter'] isn't available anymore, no idea what's going on here.
What's wrong here?
I was wondering the same and I just got it working.
You need to add:
spec.add_development_dependency "coveralls", "0.7.0"
to your .gemspec (0.7.0 is the coveralls gem latest version as the time of writing this)
make sure to run bundle installsuccessfully
and add:
require 'coveralls'
Coveralls.wear!
to the beginning of your spec_helper.rb or test_helper.rb, before requiring anything else.
Hope this helps.
Is there a way to use a gem as a library in Rails 4?
I have tried putting in a gem folder after cloning into lib folder but this doesn't seem to be working
You can set local path to gem in your Gemfile if I clearly understood the problem.
# Gemfile
gem 'my_perfect_gem', path: './path/to/my_perfect_gem'
I think it's better to set local gem location only in development and test environments, so wrap this line in a group. Unfortunately you should restart your rails server any time you've updated the gem.
May be there is a better approach such as using your gem as a part of application in lib folder – Auto-loading lib files in Rails 4
I'm trying to create a rails engine that will use javascript from a gem dependency that I have added to the engine. However I keep getting "couldn't find file 'fullcalendar'" when I put the following line in my application.js for my engine:
//= require fullcalendar
This line is loading the javascript from the gem dependency into the rails engine.
This same line will work when the gem is installed on a normal rails app (not engine). What am I missing here? Can an engine load javascript from another engine/gem?
UPDATE:
Researching on my own the issue could be that sprockets only looks for javascript inside the engine. The gem dependency is installed into vendor/cache of the parent app NOT the engine therefore //require fullcalendar fails because it is looking within the engine and the javascript for fullcalendar is in the parent application.
What confuses me is that if I include fullcalendar in the parent application gemfile explicitly than I am able to access it in the engine. This doesn't make sense to me. In both instances the full calendar gems javascript is in the parent app, but the behavior is different. Including the gem in two places is unappelaing to me and doesn't seem like a proper solution. Any thoughts?
I had some trouble with this in the past.
App > Engine 1 > Engine 2
Engine 1 and Engine 2 worked fine on the app. I created a dummy app in Engine 1 to test Engine 2's functionality, also worked fine. But when I put Engine 1 in App it didn't work at all.
My big mistake here was only including Engine 1 in App, Engine 2 has to be included as well!
Inheritance does not work for Gemfiles, just dependencies.
A little late to the party, but I recently had the same issue. Here is my post to describe it the solution http://grantrklinsing.com/articles/2013/01/10/adding-3rd-party-assets-to-a-rails-gem.html. Hope it helps if you didn't get it working.
Does the fullcanendar gem you're using come with an installer? Some gems come with installers for model migrations, assets, views, config files, etc.
If you're referring to the fullcalendar-rails gem it comes with an installer that you have to run using the
rails g fullcalendar:install command.
If the gem doesn't come with an installer you can manaully clone the gem to your local machine by running git clone gem_github_repository_url_here.git which will enable you to navigate the gem's folders and you'll have direct access to any of the assets that the gem uses which can be copied over to your rails application.
If your Engine has a dependency added through the gemspec file, you need to require this dependency directly before Engine initialization.
app/lib/app/engine.rb
require 'fullcalendar-rails'
module App
class Engine < ::Rails::Engine
isolate_namespace App
end
end
I have a problem with Activemessaging plugin and rails3 app.
my gemfile is
gem 'sqlite3'
gem 'activemessaging', :git=>'git://github.com/spraints/activemessaging.git'
gem 'stomp'
gem 'daemons'
After that activemessaging folder appeared in vendor
After bundle install I want to create processor with generator
rails generate processor Test
And I see this output:
ActiveMessaging: adapter reliable_msg not loaded: no such file to load -- reliable-msg
ActiveMessaging: adapter wmq not loaded: no such file to load -- wmq/wmq
ActiveMessaging: adapter beanstalk not loaded: no such file to load -- beanstalk-client
ActiveMessaging: no '/home/ruby/myapp/script/config/messaging.rb' file to load
ActiveMessaging: Loading script/app/processors/application.rb
Rails available: Adding dispatcher prepare callback.
ActiveMessaging: no '/home/ruby/myapp/script/config/messaging.rb' file to load
Could not find generator processor.
What did I miss ? What should I do step by step to make it works. Thank you
What guide or blog article are you using for installation?
http://code.google.com/p/activemessaging/wiki/Installation
Their wiki doesn't resemble the steps you're taking to install, since they recommend using it as a plugin.
EDIT:
After looking at their active issues on Google Code, this project doesn't support Rails 3 yet. At least, major features are missing such as all the generators being in the wrong place such that rails generate won't know about them.
If you want to go it on your own, you'll have to do a bunch of manual config:
http://code.google.com/p/activemessaging/wiki/Configuration
use https://github.com/kookster/activemessaging repo in your gemfile
gem 'activemessaging', :git => 'git#github.com:kookster/activemessaging.git'
Then you can use the rails 3 generators of this gem:
rails g active_messaging:install
rails g active_messaging:processor YOUR_PROCESSOR
This will create the config/broker.yml (broker config) and config/messaging.rb (queue config).
Its a very nice gem.
NOTE: Be sure to include the celluloid gem and daemons. In my gemfile:
gem 'stomp'
gem 'celluloid'
gem 'daemons'
Happy coding! .)
What is the difference between having require 'gem_name' in a controller and config.gem "gem_name" in environments.rb? I'm new to RoR, and am looking through an app and can't work out the difference. Thanks for reading.
"environments.rb" is a file that contains various configuration setting for your application, e.g. which gem the application needs to run correctly (mainly for portability). They have to be specified using config.gem "gem_name". This post about Gem Dependencies could help you.
With require "gem_name" you can explictly import a gem into your code in order to be able to use it´s classes.
config.gem in your environment.rb is needed to set up the correct rails environment. For example if you download a ruby app from github you can run rake gems:install from the application directory and all the correct versions of the required gems will be installed.
require in a controller is like import in vb.net and allows the classes in that gem to be used in your controller.