简体   繁体   English

Rails + Bower问题与资产路径

[英]Rails + Bower issue with assets path

I have install "Tinymce" though bower into my rails app in vendor/assets/bower_components/tynymce-dist 虽然我在rails / assets / bower_components / tynymce-dist中的rails应用程序中安装了“Tinymce”

I include js assets in application.js and it works ok 我在application.js中包含了js资产,它运行正常

//= require tinymce-dist

then I include css files in application.css 然后我在application.css中包含css文件

@import 'tinymce-dist/skins/lightgray/skin.min.css'

it works, but I have an error in rails console 它工作,但我在rails控制台中有错误

 ActionController::RoutingError (No route matches [GET] "/assets/skins/lightgray/skin.min.css"):

and in chrome console 并在chrome控制台中

GET http://localhost:3000/assets/skins/lightgray/skin.min.css

it calls from tinymce script in that way 它以这种方式从tinymce脚本调用

skinUrl = tinymce.baseURL + '/skins/' + skin;

looks like it calls absolut url. 看起来它叫absolut网址。

One solucion is to use Tinymce gem, but I dont want to use this way. 一个解决方案是使用Tinymce gem,但我不想这样使用。

How to fix this problem. 如何解决这个问题。

If you're using Bower in your Rails app, you'll do well looking into Rails Assets : 如果你在Rails应用程序中使用Bower ,你会很好地研究Rails资产

在此输入图像描述

This basically allows you to include bower-enabled assets as gems. 这基本上允许您将支持bower的资产作为宝石。 You just have to search for the respective gem on their app, and then add the gem to your Gemfile: 您只需要在他们的应用程序上搜索相应的gem,然后将gem添加到您的Gemfile:

在此输入图像描述

RA actually have TinyMCE-dist already: RA实际上已经有TinyMCE-dist了:

在此输入图像描述


I would personally recommend using Rails Assets - I can delete the answer if you'd rather not. 我个人建议使用Rails Assets - 如果你不愿意,我可以删除答案。 It will give you the benefits of bower and the dependability of the gem system: 它将为您提供凉亭的好处和宝石系统的可靠性:

#Gemfile
source https://rubygems.org
source https://rails-assets.org #-> add this line

gem 'rails-assets-tinymce-dist'

Then add the following to your JS & CSS assets: 然后将以下内容添加到JS&CSS资产中:

#app/assets/javascripts/application.js
//= require tinymce-dist/tinymce.js

#app/assets/stylesheets/application.css
@import 'tinymce-dist/skins/lightgray/skin'

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM