Summernote Ruby Gem不使用表单(RoR)

时间:2013-12-19 14:32:05

标签: ruby-on-rails ruby gem

我最近在我的Gemfile中包含了Summernote gem,并在.js和.css文件中包含了所有必要的行(在http://rorlab.github.io/summernote-rails/找到的内容)

我想使用Summernote在我的食谱数据库中编辑我的“步骤”text_area。没有Summernote(见下图)

,表格完美无缺

但是当我按照以下方式分配我的字段时添加了'summernote'类:

<%= f.text_field :steps, class: 'summernote', placeholder: "Add step", id: "add_steps" %>

我显示了summernote输出但是我的文本输出丢失了,提交按钮将不起作用。

enter image description here

任何想法?

在链接中的说明中,我被告知要添加到recipe.js.coffee脚本中。我添加了以下内容:

summer_note = $('add_steps')

summer_note.summernote

height:300  
 toolbar: [
             ['insert', ['picture', 'link']], // no insert buttons
             ["table", ["table"]], 
             ["style", ["style"]], 
             ["fontsize", ["fontsize"]], 
             ["color", ["color"]], 
             ["style", ["bold", "italic", "underline", "clear"]], 
             ["para", ["ul", "ol", "paragraph"]], 
             ["height", ["height"]], 
             ["help", ["help"]]
         ]

summer_note.code summer_note.val()


summer_note.closest('form').submit ->
 alert $('add_steps').code()[0]
summer_note.val summer_note.code()[0]
true

我在_step_form.html.erb文件中的Javascript是:

<script>
$(document).ready(function() {
  $('.summernote').summernote({
  toolbar: [
    //['style', ['style']], // no style button
    ['style', ['bold', 'italic', 'underline', 'clear']],
    ['fontsize', ['fontsize']],
    ['color', ['color']],
    ['para', ['ul', 'ol', 'paragraph']],
    ['height', ['height']],
    //['insert', ['picture', 'link']], // no insert buttons
    //['table', ['table']], // no table button
    //['help', ['help']] //no help button
  ]
});
});
</script>

我是RoR的新手所以任何帮助表示赞赏!谢谢。如果我错过了什么,请告诉我。

1 个答案:

答案 0 :(得分:1)

您需要在“add_steps”ID中添加主题标签。

即,更改此选择器:

summer_note = $('add_steps')

到此:

summer_note = $('#add_steps')