Rails 3.1 应用程序中的 CKEditor 文本区域为空白
我试图将 ckeditor 嵌入到表单中,但它只是显示为空白。文本区域只是一个空白区域,我希望在其中找到 html 编辑器窗口。我有一个模型,我希望“描述”字段为 html 文本。我觉得用ckeditor来编辑会比较方便。我不明白为什么文本字段编辑器没有显示。
我有一个 Rails 3.1 应用程序,并且正在使用 ckeditor gem(版本 3.6.2)。我已经下载了 ckeditor 并将其放入我的 asset/javascripts 文件夹中。
在我的 application.html.erb 文件中,我有这样一行:
<%= javascript_include_tag "ckeditor/ckeditor.js" %>
在我看来,我有一些这样的代码:
<%= form_for(@k) do |f| %>
<%= f.cktext_area :description, :toolbar => 'Full', :width => 800, :height => 400 %>
这会生成这样的 html:
<textarea id="k_description" rows="20" name="k[description]" cols="40" style="visibility: hidden;"></textarea>
<script type="text/javascript">
//<![CDATA[
if (CKEDITOR.instances['k_description']) {CKEDITOR.remove(CKEDITOR.instances['k_description']);}CKEDITOR.replace('k_description', { height: 400,language: 'en',toolbar: 'Full',width: 800 });
//]]>
</script>
这一切看起来应该可以工作,但事实并非如此。我缺少什么?
I'm trying to embedd a ckeditor into a form and it just comes up blank. The text area is just an empty space where I expect to find an html editor window. I have a model where I want the "description" field to be html text. I thought it would be convenient to use ckeditor to edit it. I can't work out why the text field editor is not showing.
I've got a rails 3.1 app, and I'm using the ckeditor gem (version 3.6.2). I've downloaded ckeditor and put it in my assets/javascripts folder.
In my application.html.erb file I have this line:
<%= javascript_include_tag "ckeditor/ckeditor.js" %>
In my view I have some code like this:
<%= form_for(@k) do |f| %>
<%= f.cktext_area :description, :toolbar => 'Full', :width => 800, :height => 400 %>
This generates html like this:
<textarea id="k_description" rows="20" name="k[description]" cols="40" style="visibility: hidden;"></textarea>
<script type="text/javascript">
//<![CDATA[
if (CKEDITOR.instances['k_description']) {CKEDITOR.remove(CKEDITOR.instances['k_description']);}CKEDITOR.replace('k_description', { height: 400,language: 'en',toolbar: 'Full',width: 800 });
//]]>
</script>
It all looks like it should work, but it doesn't. What am I missing?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
由于 CKeditor 链接其依赖项的方式,您必须将其移至公用文件夹。 Rails 3.1.1 中有一个辅助选项,我相信它可以解决这个问题。 (:摘要=>假)。
Because of the way CKeditor links its dependancies you'll have to move it to the public folder. There is a helper option coming in Rails 3.1.1 which I believe will fix this problem. (:digest => false).