I'm using Spree 0.70.3, Rails 3.1.3, and a custom fork of the Spree Editor plugin. (N.B. the relevant code for this fork hasn't changed from master.)
When I request a page which should get TinyMCE on a text area, I see this error in my development log:
Error compiling asset admin/all.js:
Sprockets::FileNotFound: couldn't find file 'tinymce-jquery'
(in <gemset-path>/bundler/gems/spree_editor-48cdfcfaf7bd/app/assets/javascripts/admin/spree_editor.js:9)
The line in question looks like this:
//= require tinymce-jquery
The editor depends on the tinymce-rails gem, which has a few candidates for the file in question:
assets/vendor/tinymce/jquery-tinymce.js
assets/precompiled/tinymce/jquery.tinymce.js
assets/precompiled/tinymce/tiny_mce_jquery.js
assets/integration/tinymce-jquery.js
The README for that gem says the require line quoted above is correct, however. None of the gem's paths are in Sprockets' search path as shown by putting Rails.application.config.assets.paths into the console.
Should I be adding the gem's path to the Sprockets search path somehow, or is this something the gem isn't doing correctly?
I assume you cannot precompile the gem, I had a similar issue so what i did was to download the javascript plugin from the site manually and copied the directories into my rails app. or i also tried to use a lower version of tinymce-rails gem and it worked.
Related
I have a rails-application (rails 5.2) with opal (0.11.1) running.
I would like to use erb-templates on client site. I followed the steps described in the official opal-docs (http://opalrb.com/docs/guides/v0.11.1/templates.html), but requiring the opalerb-file fails. sprocket claims the file could not be found:
couldn't find file 'views/user' with type 'application/javascript'
File views/user.opalerb exists.
It seems that sprockets does not handle / recognize opalerb-files, although I don't find a hint that things have to be configured.
How can I make opal with sprockets find and compile this file?
I ran into the same problem (Rails 5.2.2, Opal 0.11.4). The "opalerb" extension was not being correctly registered with Tilt and Sprockets. I addressed this locally by creating a file called "opal.rb" in config/initializers with one line:
require 'opal/sprockets/erb'
Alternatively, I was also able to fix the problem by explicitly including "opal-sprockets" in my Gemfile, pulling directly from the master branch in Github:
gem 'opal-sprockets', git: 'https://github.com/opal/opal-sprockets.git'
The final option seems to be to include "opal-haml" (even if you don't intend to use HAML). This seems to trigger initialization, although I haven't investigated why.
gem 'opal-haml'
I'm trying to wrap the bootstrap-sass gem inside another gem (let's call it my-engine). Along the way, I'm building a small Rails application to test things out. As a first step, I wanted to make sure I could get bootstrap-sass working directly in my Rails application. The Gemfile for the Rails app looks like this:
gem 'bootstrap-sass', '3.3.1.0'
gem 'my-engine, path: "~/dev/my-engine"
This works fine. The bootstrap assets are loaded into my Rails application and everything looks good. Now, I want to take bootstrap-sass out of my Rails app and let it load through my-engine. So, my Rails application Gemfile now looks like:
gem 'my-engine, path: "~/dev/my-engine"
The .gemspec for my-engine has:
spec.add_runtime_dependency 'bootstrap-sass', '3.3.1.0'
I can re-bundle the my-engine gem with no problems. I can re-bundle the Rails application with no problems. However, when I refresh the page of the Rails app, I get the following error:
File to import not found or unreadable: bootstrap-sprockets.
That break occurs when sprockets is trying to build the application.css file. Sometimes this will pass and I'll get a different error about missing the bootstrap.js javascript file when the application.js is being built.
Why is this happening? I'm wondering if it has something to with the fact that I'm developing the gems locally and haven't published them, although I'm not sure why that would affect bootstrap-sass which is published. I'm using bundler 1.5.3.
Make sure 'bootstrap-sass' is required in your engine. One sensible place to do this is in your lib/my-engine.rb file:
require 'bootstrap-sass'
Adding the bootstrap-sass gem as a runtime dependency in the .gemspec isn't enough when you're trying to wrap gems.
As you want to use more and more scss/js/coffeescript libraries, you may want to consider moving to bower vs gemfiles as the source for bootstrap-sass-official. We use bower-rails for rake tasks and auto-configuration. It's a really lite config/rake task layer over standard bower.
Addressing your answer, bootstrap problems via the gem was one of the reasons I switched our engine over to just bower assets. We now import bootstrap-sass-official and have full control, note however that for sass files you will need to import the longer path to the source file, i.e. in our engine _application.scss:
# our custom variable overrides
#import 'overrides/variables';
#import 'bootstrap-sass-official/assets/stylesheets/bootstrap-sprockets';
#import 'bootstrap-sass-official/assets/stylesheets/bootstrap';
NOTE: if you want your app sass variables to override engine and sass variables, make sure your engine has _application.scss not application.scss, the leading underscore is critical for variable context/scope.
Thinking ahead, you may need to ignore bower transitive dependencies as we did.
(i.e. some dependencies may use 'bootstrap' while others use 'bootstrap-sass-official' etc)
We use it like this in our .bowerrc such as the following:
{
"ignoredDependencies": [
"bootstrap",
"bootstrap-sass",
"bootstrap-sass-official"
]
}
In conclusion
We have been using this for several months with success. bower-rails will install the dependencies in /vendor/assets and if referenced in your engine, you won't need to reference them at all in your application project. It has been fast and easy to maintain/add/update libraries and know exactly how files are included.
I'm trying to setup angular-chart.js in an Angular on Rails application, per github instructions. But the documentation is not specifically for Rails so I'm running into errors.
Installation instruction: http://jtblin.github.io/angular-chart.js/
For reference,
installed via bower, bower install angular-chart.js --save
added as dependency, angular.module('myModule', ['chart.js']);.
Documentation then recommends then adding <script src="bower_components/angular-chart.js/dist/angular-chart.js"></script>, but this file is not found if I add this line (think because using Rails).
Since the application is Angular ontop of Rails, I assume it needs to be added to Rails application.js file. As otherwise there is an angular no module error.
But I'm not sure exactly what needs to be added to application.js. I've tried:
chart.js
angular-chart.js
angular-chart
(prefaced by //= require)
But everything results in a Rails error,
Sprockets::FileNotFound in Boards#index
couldn't find file 'chart.js' with type 'application/javascript'
Is there a way to find out exactly what needs to be added to application.js? Or some other way to solve this?
(Apologies if this is difficult to follow.)
You can use (as you mentioned in discussion) gem browserify-rails to easily pick-up bower/node.js packages. Include gem into Gemfile, bundle install, and then install npm/bower package into app.
gem 'browserify-rails'
I am creating a gem that will contain the foundation-rails gem along w/ some common variables that are used across my applications. I have created a stylesheet at vendor/assets/stylesheets/foundation.scss. I load this from within my application as such
Gemfile
gem 'foobar-foundation-rails', path: '...'
app/assets/stylesheets/application.css
//= require foundation
This is a good starting point but how do I include the foundation-rails gem's stylesheet from within this file? I am unsure how to reference another gem's assets
I think the best approach is to put the responsibility for the require statements in your rails app's javascripts file. This is most likely not functionality you want to bury in a gem, as it hides what is happening.
Then make sure you require your gem's css file before the foundation-rails require. However you should put a dependency requirement in your gem's gemspec file to ensure that the foundation-rails gem will be installed by bundler when your gem is installed.
Also you may have to "namespace" your gems style sheet in order to avoid namespace collisions.
vendor/assets/stylesheets/foobar_foundation_rails/foundation.css
Which would change the require in your stylesheet file to
require 'foobar_foundation_rails/foundation.scss'
Lastly, the naming of a gem establishes how the gem gets required. When you use dashes Rails expects things to be required, and hence your gem's directory structure to follow
lib/foobar/foundation/rails
As opposed to an underscore naming foobar_foundation_rails
lib/foobar_foundation_rails
Unless you're going to build an "extension" to the foundation-rails gem, which would need to be called foundation-rails-foobar, you may want to go with the underscore syntax to save yourself some require headaches. The devise gem is a good example of extension gems.
I installed the Redactor gem, but after some time I decided that this gem doesn't suit my needs. I removed it from Gemfile, and also removed all of the gem's files (I suppose) in all app folders.
When I try to deploy app, the server fails to start with this error:
uninitialized constant Redactor Rails
It points to the folder which I actually removed (in models). Each time it is created while I'm pushing the app to the server (with git).
How can I completely remove ALL the files that the gem generated?
You sure did
gem uninstall redactor-rails
Remove in your application.js
//= require redactor-rails
also in your application.css
*= require redactor-rails
The gem also generated in
app/uploaders/redactor_rails_document_uploader.rb
app/models/redactor_rails/document.rb