【问题标题】:My jquery tag doesn't work into haml format我的 jquery 标记不适用于 haml 格式
【发布时间】:2018-09-28 10:21:51
【问题描述】:

我在将我的 jquery 包含到我的 haml 文件中时遇到了一些麻烦,我是新手。 我想包含一个日期选择器并将值保存到一个变量中

我已将其包含到我的 application.js 和 gem 'jquery-timepicker-addon-rails'到我的 gemfile 中:

//= require jquery-ui
//= require jquery-ui-timepicker-addon 
//= require jquery_ujs

这是什么:创建一个 var,我可以在其中存储日期时间,然后从我的用户表中将其减去 last_sign_in_at。

这是我想出的:

-$date =
  %h3 Please enter the following information:
    = form('/search', :post)
      = input(:users, :last_sign_in_at, class: "formbox")
      = submit('Submit', class: "button")

:javascript
  $(function() {
    $( "#start_date, #end_date" ).datepicker({format: 'yyyy-mm-dd'});
  });

但是,日期选择器没有出现,我很确定我的 var $date 有问题。

这是我遇到的错误:

content can't be both given on the same line as %h3 and nested within it

有什么建议吗?

【问题讨论】:

    标签: jquery ruby-on-rails haml


    【解决方案1】:

    问题是这段代码:

    %h3 Please enter the following information:
      = form('/search', :post)
        = input(:users, :last_sign_in_at, class: "formbox")
        = submit('Submit', class: "button")
    

    在这里,您尝试在 h3 标记内创建 form,这是错误的。应该是这样的:

    %h3 Please enter the following information:
    = form('/search', :post) do
      = input(:users, :last_sign_in_at, class: "formbox")
      = submit('Submit', class: "button")
    

    您可以选择将内容包含在同一行或嵌套它,如果同时尝试两者,则会引发错误。在您的代码中,您正在尝试做同样的事情(嵌套并同时包含,您的文本被包含并且表单被嵌套)。这就是它抛出错误的原因:

    content can't be both given on the same line as %h3 and nested within it
    

    【讨论】:

    • 感谢您的回答。但是,我仍然收到错误 expecting end-of-input 出现。有什么想法吗?
    • form 前面添加do,如下所示:= form('/search', :post) do
    • 确实如此。谢谢。但是,我仍然有一些问题要理解这个 datepicker 是如何工作的。我会自己解决的,非常感谢。
    猜你喜欢
    • 2022-06-10
    • 1970-01-01
    • 2013-07-08
    • 2019-07-27
    • 1970-01-01
    • 1970-01-01
    • 2019-09-16
    • 1970-01-01
    • 2011-10-17
    相关资源
    最近更新 更多