Ruby on rails 4 ECSS模式在rails中不工作
我正在尝试弹出一个模态表单来添加新的注释 HTML代码段Ruby on rails 4 ECSS模式在rails中不工作,ruby-on-rails-4,materialize,Ruby On Rails 4,Materialize,我正在尝试弹出一个模态表单来添加新的注释 HTML代码段 <a href="#add_ac" data-toggle="modal" class="waves-effect waves-light blue accent-2 white-text btn">Add Comment</a> <div id="add_ac" class="modal"> <div class="modal_content"> <%= render
<a href="#add_ac" data-toggle="modal" class="waves-effect waves-light blue accent-2 white-text btn">Add Comment</a>
<div id="add_ac" class="modal">
<div class="modal_content">
<%= render '/s_comments/form' %>
</div>
</div>
根据MaterializeCSS文档,这应该是可行的
下面是我的application.js文件的标题
//= require jquery2
//= require jquery_ujs
//= require turbolinks
//= require materialize-sprockets
//= require_tree .
谢谢。您需要在document ready函数中初始化materialize modals:
$(document).ready(function(){
// the "href" attribute of .modal-trigger must specify the modal ID that wants to be triggered
$('.modal-trigger').leanModal();
});
在这之后,他们应该出现
您仍然需要准备好rails表单以用于modals,我在这里找到了一个指南:您需要在document ready函数中初始化materialize modals:
$(document).ready(function(){
// the "href" attribute of .modal-trigger must specify the modal ID that wants to be triggered
$('.modal-trigger').leanModal();
});
在这之后,他们应该出现
您仍然需要准备好rails表单,以便使用modals,我在这里找到了一个指南:我知道这个问题很老了,但我想与大家分享一下,以防其他人遇到这个问题
如果您使用的是Rails中的标准TurboLinks,那么将侦听器附加到按钮的javascript需要放在文档的主体而不是头部。TurboLinks只会在加载新页面时替换主体,javascript不会再次运行。我知道这个问题很老,但我想与大家分享一下,以防其他人遇到这个问题
如果您使用的是Rails中的标准TurboLinks,那么将侦听器附加到按钮的javascript需要放在文档的主体而不是头部。TurboLinks只会在加载新页面时替换主体,javascript不会再次运行。您正在初始化模态触发器的模态类
$('.modal-trigger').leanModal({
dismissible: true
})
但是您没有调用/引用锚点标记中的类
<a href="#add_ac" data-toggle="modal" class="waves-effect waves-light blue accent-2 white-text btn">Add Comment</a>
<a href="#add_ac" data-toggle="modal" class=" modal-trigger waves-effect waves-light blue accent-2 white-text btn">Add Comment</a>
因此,您只需要在锚定标记中添加模态触发器
<a href="#add_ac" data-toggle="modal" class="waves-effect waves-light blue accent-2 white-text btn">Add Comment</a>
<a href="#add_ac" data-toggle="modal" class=" modal-trigger waves-effect waves-light blue accent-2 white-text btn">Add Comment</a>
它应该可以工作,我也不知道为什么要使用数据切换。您正在初始化模态触发器的模态类
$('.modal-trigger').leanModal({
dismissible: true
})
但是您没有调用/引用锚点标记中的类
<a href="#add_ac" data-toggle="modal" class="waves-effect waves-light blue accent-2 white-text btn">Add Comment</a>
<a href="#add_ac" data-toggle="modal" class=" modal-trigger waves-effect waves-light blue accent-2 white-text btn">Add Comment</a>
因此,您只需要在锚定标记中添加模态触发器
<a href="#add_ac" data-toggle="modal" class="waves-effect waves-light blue accent-2 white-text btn">Add Comment</a>
<a href="#add_ac" data-toggle="modal" class=" modal-trigger waves-effect waves-light blue accent-2 white-text btn">Add Comment</a>
它应该可以工作,我也不知道为什么要使用数据切换。这是否意味着我需要包含一个单独的js文件并将其加载到正文中?我对rails和许多资产的处理方式还相当陌生。@jabbajac我只需要在下面的文章中加入js MuteMinute。您可以将它包含在另一个文件中,但我只是将它放在带有:javascript标记的视图中。我不知道这只是一个HAML标签,还是它在ERB中也能工作。这是否意味着我需要包含一个单独的js文件并将其加载到正文中?我对rails和许多资产的处理方式还相当陌生。@jabbajac我只需要在下面的文章中加入js MuteMinute。您可以将它包含在另一个文件中,但我只是将它放在带有:javascript标记的视图中。我不知道这仅仅是一个HAML标签,还是在ERB也适用。