对于Formtastic,Rails未定义方法`html_safe'

时间:2018-04-03 11:06:25

标签: ruby-on-rails formtastic

我正在使用Formtastic并在我拥有的表格上:

// ==UserScript==
// @name         Burning Series
// @namespace    http://bs.to/
// @version      1.0
// @description  -
// @author       Me
// @match        https://bs.to/andere-serien
// @require      https://code.jquery.com/jquery-3.3.1.min.js
// @grant        GM_addStyle
// ==/UserScript==

GM_addStyle('.contextMenuParent { position: relative;  }');
GM_addStyle('.contextMenuContainer { position: absolute; background: gray; z-index: 100; -webkit-box-shadow: 10px 10px 31px -1px rgba(0,0,0,0.75);-moz-box-shadow: 10px 10px 31px -1px rgba(0,0,0,0.75);box-shadow: 5px 5px 15px -1px rgba(0,0,0,0.75);}');
GM_addStyle('.contextMenu { display: grid; padding: 4px; width: 200px; border: 1px solid black;  color: black; }');
GM_addStyle('.contextMenu li { border-bottom: 1px solid gray; }');
GM_addStyle('.contextMenu li:hover { cursor: pointer; color: red; }');

var contextMenuLinks =
    "<li class='contextMenu01'>A</li>"+
    "<li class='contextMenu02'>B</li>" +
    "<li class='contextMenu03'>C</li>" +
    "<li class='contextMenu04'>D</li>" +
    "<li class='contextMenu05'>E</li>" +
    "<li class='contextMenu06'>F</li>";


$(document).ready(function() {

    $("div.genre > ul > li").each(function(i, obj) {

        $(this).addClass("contextMenuParent");

        $(this).contextmenu(function(e) {
            e.preventDefault();

            $(".contextMenuContainer").remove();

            $(this).append("<div class='contextMenuContainer'><ul class='contextMenu'>" + contextMenuLinks + "</ul></div>");

            // Calculate the offset coordinates and set CSS rules
            var off = $(this).offset();
            var scroll = $(window).scrollTop();
            $(this).find(".contextMenuContainer").css({
                'position': 'fixed',
                'left': off.left + 'px',
                'top': (off.top + $(this).outerHeight() - scroll) + 'px'
            });

        });
    });

    // Move the menu with window scroll
    $(window).on('scroll', function(){
        if($(".contextMenuContainer").length) {
            var $elem = $(".contextMenuContainer").parents(".contextMenuParent");
            var off = $elem.offset();
            var scroll = $(window).scrollTop();
            $(".contextMenuContainer").css('top', (off.top + $elem.outerHeight() - scroll) + 'px');
        }
    });

    $(document).on("click", ".contextMenu li", function() {
        var c = $(this).attr("class");

        var title = $(this).closest(".contextMenuParent").find("a").attr("title");

        $(".contextMenuContainer").remove();
    });

});

然后我用

验证字段
<%= f.input :open_date, :as => :string, :input_html => {:class => 'datepicker'}, :start_date => Date.today, label: 'OPEN' %>

如果我提交带有空字段的表单,则返回:

validates :open_date, presence: true

除了

之外,我找不到任何其他方式来调用datepicker
NoMethodError in Clients#create

Completed 500 Internal Server Error in 44ms (ActiveRecord: 5.7ms)



ActionView::Template::Error (undefined method `html_safe' for Formtastic::Util:Module
Did you mean?  html_safe?):
     6:   <div class="row">
     7: 
     8:     <div class="col-sm-3">
     9:       <%= f.input :open_date, :as => :string, :input_html => {:class => 'datepicker'}, :start_date => Date.today, label: 'OPEN' %>
    10:     </div>
    11: 
    12:     <div class="col-sm-3">

如何解决问题?

1 个答案:

答案 0 :(得分:0)

问题是我使用的是formtastic-bootstrap,问题已经报告here

所以我想我别无选择,只能移除宝石。