在 rails 中,tinymce 的工具栏未显示
In rails, tinymce's toolbar isn't showing
我已经安装了 tinymce gem。我的 tinymce 可以处理 html 标签,但工具栏不出现。这是我的视图文件的代码:
<%= tinymce_assets %>
<div class="container">
<%= form_for(@product) do |f| %>
<table summary="Product for fields" class="table table-striped">
<tr>
<th>Title</th>
<td><%= f.text_field(:title) %></td>
</tr>
<tr>
<th>Description</th>
<!--td><%= f.text_field(:description) %></td-->
<td><%= f.text_area :description, :class => "tinymce", :rows => 2, :cols => 120 %></td>
</tr>
<tr>
<th>Price</th>
<td><%= f.text_field(:price) %></td>
</tr>
</table>
<div class="form-buttons">
<%= f.submit "Create Products", :class => 'btn btn-primary pull-right' %>
</div>
<% end %>
<%= link_to 'Back', products_path, :class => 'btn btn-info' %>
</div>
<%= tinymce %>
这是我的配置文件(我的意思是tinymce.yml):
theme_advanced_toolbar_location: top
theme_advanced_toolbar_align: left
theme_advanced_statusbar_location: bottom
theme_advanced_buttons3_add:
- tablecontrols
- fullscreen
menubar: false
toolbar:
[ styleselect | bold italic | link image | code ]
plugins:
- link
- image
这里是 application.js 文件
$(document).on('ready page:load', function () {
if (typeof tinyMCE != 'undefined') {
alert("Hello! I am an alert box!!");
tinyMCE.init({
selector: "textarea.tinymce",
toolbar: [
"styleselect | bold italic | alignleft aligncenter alignright alignjustify",
"bullist numlist outdent indent | link image | code | codesample"
],
plugins: "image,link,code,codesample,autoresize,imagetools,media,table,insertdatetime,charmap,print,preview,anchor,searchreplace,visualblocks,fullscreen"
});
} else {
setTimeout(arguments.callee, 50);
}
});
当我运行这段代码时,浏览器控制台显示以下错误:ReferenceError: Can't find variable: TinyMCERails。而且我找不到解决方案。
好的,问题是如果我们使用那个配置文件,我们也不能使用 application.js 文件。因此,只需删除 application.js 文件就可以解决我的问题。
我已经安装了 tinymce gem。我的 tinymce 可以处理 html 标签,但工具栏不出现。这是我的视图文件的代码:
<%= tinymce_assets %>
<div class="container">
<%= form_for(@product) do |f| %>
<table summary="Product for fields" class="table table-striped">
<tr>
<th>Title</th>
<td><%= f.text_field(:title) %></td>
</tr>
<tr>
<th>Description</th>
<!--td><%= f.text_field(:description) %></td-->
<td><%= f.text_area :description, :class => "tinymce", :rows => 2, :cols => 120 %></td>
</tr>
<tr>
<th>Price</th>
<td><%= f.text_field(:price) %></td>
</tr>
</table>
<div class="form-buttons">
<%= f.submit "Create Products", :class => 'btn btn-primary pull-right' %>
</div>
<% end %>
<%= link_to 'Back', products_path, :class => 'btn btn-info' %>
</div>
<%= tinymce %>
这是我的配置文件(我的意思是tinymce.yml):
theme_advanced_toolbar_location: top
theme_advanced_toolbar_align: left
theme_advanced_statusbar_location: bottom
theme_advanced_buttons3_add:
- tablecontrols
- fullscreen
menubar: false
toolbar:
[ styleselect | bold italic | link image | code ]
plugins:
- link
- image
这里是 application.js 文件
$(document).on('ready page:load', function () {
if (typeof tinyMCE != 'undefined') {
alert("Hello! I am an alert box!!");
tinyMCE.init({
selector: "textarea.tinymce",
toolbar: [
"styleselect | bold italic | alignleft aligncenter alignright alignjustify",
"bullist numlist outdent indent | link image | code | codesample"
],
plugins: "image,link,code,codesample,autoresize,imagetools,media,table,insertdatetime,charmap,print,preview,anchor,searchreplace,visualblocks,fullscreen"
});
} else {
setTimeout(arguments.callee, 50);
}
});
当我运行这段代码时,浏览器控制台显示以下错误:ReferenceError: Can't find variable: TinyMCERails。而且我找不到解决方案。
好的,问题是如果我们使用那个配置文件,我们也不能使用 application.js 文件。因此,只需删除 application.js 文件就可以解决我的问题。