- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我的 new.html.erb 工作正常。
但是在我的 edit.html.erb 中,假设我有 3 个现有部门...
每当我单击“添加部门”链接(以添加另一个字段)时,它都会继续位于现有部门上方,而不是下方。
顺便说一句,我协会说部门有很多部门,部门也属于部门。
在我的 Controller 中:有我的新方法和编辑方法
def new
@division = Division.new
@division.departments.build
end
def edit
@division = Division.find(params[:id])
end
我需要 cocoon js 文件,因此我使用默认值,而不是覆盖其他内容。
cocoon.js
(function($) {
function replace_in_content(content, regexp_str, with_str) {
reg_exp = new RegExp(regexp_str);
content.replace(reg_exp, with_str);
}
function trigger_removal_callback(node) {
node.parent().parent().trigger('removal-callback');
}
$('.add_fields').live('click', function(e) {
e.preventDefault();
var $this = $(this),
assoc = $this.data('association'),
assocs = $this.data('associations'),
content = $this.data('template'),
insertionMethod = $this.data('association-insertion-method') || $this.data('association-insertion-position') || 'before';
insertionNode = $this.data('association-insertion-node'),
insertionCallback = $this.data('insertion-callback'),
removalCallback = $this.data('removal-callback'),
regexp_braced = new RegExp('\\[new_' + assoc + '\\]', 'g'),
regexp_underscord = new RegExp('_new_' + assoc + '_', 'g'),
new_id = new Date().getTime(),
newcontent_braced = '[' + new_id + ']',
newcontent_underscord = '_' + new_id + '_',
new_content = content.replace(regexp_braced, '[' + new_id + ']');
if (new_content == content) {
regexp_braced = new RegExp('\\[new_' + assocs + '\\]', 'g');
regexp_underscord = new RegExp('_new_' + assocs + '_', 'g');
new_content = content.replace(regexp_braced, '[' + new_id + ']');
}
new_content = new_content.replace(regexp_underscord, newcontent_underscord);
if (insertionNode){
insertionNode = insertionNode == "this" ? $this : $(insertionNode);
} else {
insertionNode = $this.parent();
}
var contentNode = $(new_content);
// allow any of the jquery dom manipulation methods (after, before, append, prepend, etc)
// to be called on the node. allows the insertion node to be the parent of the inserted
// code and doesn't force it to be a sibling like after/before does. default: 'before'
insertionNode[insertionMethod](contentNode);
$this.parent().trigger('insertion-callback');
});
$('.remove_fields.dynamic').live('click', function(e) {
var $this = $(this);
trigger_removal_callback($this);
e.preventDefault();
$this.closest(".nested-fields").remove();
});
$('.remove_fields.existing').live('click', function(e) {
var $this = $(this);
trigger_removal_callback($this);
e.preventDefault();
$this.prev("input[type=hidden]").val("1");
$this.closest(".nested-fields").hide();
});
})(jQuery);
在我的_form.html.erb中
<div class="new-div-box">
<%= simple_form_for [:admin, @division] do |f| %>
<%= f.input :name, :label => "Division Name"%>
<div>
<div>
<%= f.simple_fields_for :departments do |department| %>
<%= render 'department_fields', :f => department %>
<% end %>
</div>
<%=link_to_add_association "Add Department", f, :departments,class: "btn btn-inverse" %>
</div>
<%= f.submit :class=>"btn btn-primary submit_btn_division" %>
<% end %>
</div>
我渲染的是_department_fields.html.erb
<div class="nested-fields">
<%= f.input :name, :label => "Department Name" %>
<%= link_to_remove_association raw("<img src='../../../assets/remove.png' width='25px' height='25px'>"), f %>
</div>
我想知道为什么新添加的字段高于我的 edit.html.erb 中的现有字段
最佳答案
我认为它会寻找一个带有关联的 div 作为包装嵌套字段的 id。
所以你的看法
<div id="departments">
<%= f.simple_fields_for :departments do |department| %>
<%= render 'department_fields', :f => department %>
<% end %>
<div class="links">
<%=link_to_add_association "Add Department", f, :departments,class: "btn btn-inverse" %>
</div>
</div>
关于jquery - cocoon Nested_form 将字段添加到 edit.html.erb 中现有对象的上方而不是下方,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13816752/
我在 Rails 应用程序上使用 chessboard-0.3.0.js。由于 Rails Assets 管道的问题,我必须编辑渲染图像的 js 代码的每个部分,例如 Pieces。chessboar
我有一个简单的 fixture.yml 文件: label: body: "" 问题是 ERB 代码被解析为加载 fixture 的一部分,而我实际上希望正文字面意思是“”(未插值)。 如何逃
这是erb3.rb require 'erb' weekday = Time.now.strftime('%A') simple_template = "Today is ." renderer =
name.html.erb 和 name.erb 有什么区别?特别是,是否有任何原因导致 name.erb 不好用? 我知道 name.html.erb 是约定 - 这表示 HTML 模板和 ERB
.erb、.rhtml 和 .html.erb 之间有什么区别? 最佳答案 没什么,真的。这只是 Rails 1 和 Rails 2 之间理念的改变。在 Rails 2 之前,有 file.rhtml
我想知道是否有一个 API 可以很好地支持 eRuby (erb) 和 JavaScript 突出显示、语法分析和代码辅助。 我已经尝试过使用 Aptana 来使用 Eclipse RadRails
我正在尝试在 Rails 应用程序上的示例 ruby 上实现 jquery。我刚刚开始探索js。我知道我在 js/jquery 方面还有很多东西要学。现在有件事让我很困惑。 我有一个 js.erb
我有一个导航栏,它显示未读消息数。未读计数必须在导航栏文本中进行格式化,因此我使用了以下内容: false}).count(:id, :distinct => true).to_s}", conve
我正在编写一个显示代码和输出的样式指南。它目前的结构使得代码只需要描述一次,并以其原始版本和解释版本显示,如下所示: #{ image_tag 'image.png' } PLACE_THE
我的大多数 js.erb 文件底部都包含类似这样的内容: $("#flash_message").html(" "note")) %>"); $("#flash_message").fadeOut(2
我的目标是使用相同的 Controller 调用 html.erb 和 js.erb 文件,但它只调用我的 html 文件。 我的 js 没有被调用。 Controller /categories_c
尝试将* .html.slim View 转换为* .html.erb。 我看了以下两个问题: How can I convert html.slim to html.erb?-从控制台调用时获取un
我正在 Eclipse 中开发 jRuby on Rails 应用程序。我最近安装了 Aptana 以更好地支持 rails 文件。这为大多数文件类型提供了合理的突出显示和支持,包括“html.erb
过去几天我一直在尝试理解 Rails 上 AJAX 的不同方面。在阅读了一些介绍后,我对 Rails 内置的 UJS 功能有了一定的了解。我编写的一个小玩具应用程序的示例,我想在其中引入一些 AJAX
我在不同模型的 ajax 响应之间有重复的 js.erb 代码。我想通过将参数传递到 js.erb 部分来重构重复的 js.erb 代码。 如何从 js.erb 文件渲染 js.erb 部分? 最佳答
我的 Rails 应用程序正在为特定窗口使用 js.erb View 而不是 html.erb View 。这在实践中很好用,但是当我对 capybara 使用 cucumber 测试时,它给我一个错
我尝试使用 rails-erb-loader。 在我的 home.component.ts import templateString from './home.component.html'; 我有
我刚刚花了最后一个小时浏览 Atom 论坛寻找答案。有没有人想通了? 最佳答案 core: customFileTypes: "text.html.ruby": [
我没能找到讨论 create.js.erb 和 destroy.js.erb 如何适合 Rails 3 应用程序的文档。 app > Controller 中这些类型的 Javascript 文件背后
我目前正在尝试将 vue.js v-model 包含到我的 erb 表单输入标签中,但我找不到正确的语法。 这是我的代码目前的样子: 如果有任何想法,我将不胜感激。谢谢! 最佳答案 试试这
我是一名优秀的程序员,十分优秀!