小编Jen*_*örk的帖子

TinyMCE extended_valid_elements似乎没有这样做

我希望TinyMCE允许在图像上使用样式等属性,但我无法让它真正起作用.我已经阅读了文档以及网络但无法找到解决方案.

问题是'extended_valid_elements'命令不能完成这项工作.每次我在编辑器中按"保存",它都会忽略样式属性.我只是想知道是否有人有同样的问题?

我有一个TinyMCE设置,如下所示(一切正常,但不是extended_valid_elements):

$('textarea.editor').tinymce({
    // Location of TinyMCE script
    script_url : '/assets/js/tiny_mce/tiny_mce.js',
    height : 400,
    width : 665,

    extended_valid_elements : "img[class|src|border=0|alt|title|hspace|vspace|width|height|align|onmouseover|onmouseout|name|style]",

    // General options
    theme : "advanced",
    plugins : "pagebreak,style,layer,table,save,advhr,advimage,advlink,emotions,iespell,inlinepopups,insertdatetime,preview,media,searchreplace,print,contextmenu,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras,template,imagemanager",

    // Theme options
    theme_advanced_buttons1 : "save,newdocument,|,bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,styleselect,formatselect,fontselect,fontsizeselect",
    theme_advanced_buttons2 : "cut,copy,paste,pastetext,pasteword,|,search,replace,|,bullist,numlist,|,outdent,indent,blockquote,|,undo,redo,|,link,unlink,anchor,image,cleanup,help,code,|,insertdate,inserttime,preview,|,forecolor,backcolor",
    theme_advanced_buttons3 : "tablecontrols,|,hr,removeformat,visualaid,|,sub,sup,|,charmap,emotions,iespell,media,advhr,|,print,|,ltr,rtl,|,fullscreen",
    theme_advanced_buttons4 : "insertlayer,moveforward,movebackward,absolute,|,styleprops,|,cite,abbr,acronym,del,ins,attribs,|,visualchars,nonbreaking,template,pagebreak,insertimage",
    theme_advanced_toolbar_location : "top",
    theme_advanced_toolbar_align : "left",
    theme_advanced_statusbar_location : "bottom",
    theme_advanced_resizing : true,

    relative_urls : false,
    skin : "o2k7",
    skin_variant : "silver",

    // Example content CSS …
Run Code Online (Sandbox Code Playgroud)

jquery tinymce

6
推荐指数
1
解决办法
3386
查看次数

Rails 4 HABTM对关联的自定义验证

我有一个简单的场景,但我似乎无法找到适用于Rails 4的任何建议的解决方案.我想简单地添加一个自定义验证器来检查我的HABTM关联之间存储的关联量.更容易说和完成,令我惊讶?

我已经搜索了一个解决方案,但最终只得到了旧版本Rails的答案.我有以下内容:

class User < ActiveRecord::Base

  has_and_belongs_to_many :roles
  after_save :check_maximum_number_of_roles

  .
  .
  .

  private

  def check_maximum_number_of_roles
    if self.roles.length > 3
      errors.add(:roles, 'Users can only have three roles assigned.')
      return false
    end
  end

end

class Role < ActiveRecord::Base

  has_and_belongs_to_many :users

end
Run Code Online (Sandbox Code Playgroud)

我使用的原因after_save是因为据我所知,存储的关联在添加后首先可用.我也试过写一个自定义验证器(例如validate: :can_only_have_one_role),但这也不起作用.

我以下面的方式添加关联,并在rails控制台中完成此操作(应该可以正常工作?):

user.roles << role
Run Code Online (Sandbox Code Playgroud)

然而,它为用户添加了多个角色,并不关心任何类型的验证.

非常感谢,谢谢!

validation activerecord ruby-on-rails has-and-belongs-to-many ruby-on-rails-4

6
推荐指数
1
解决办法
3021
查看次数