- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我无法解决这个问题,我正在使用 simple_form 并且需要使用模型渲染表单,但问题是具有 escape_javascript 的 js 文件无法在每个文件中获取模型
new.html.erb:
<div id="myModal" class="modal fade">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-body">
<%= simple_form_for @team do |t|%>
<div class="row">
<ul class="team_name">
<li><%=t.input :name, label: 'Nombre del Team'%></li>
<%=t.fields_for :checkbox do |c|%>
<li><%=c.input :check, as: :boolean, label: 'Crear y Agregar Usuarios'%></li>
<li><%= t.association :users, label: "Buscar Usuarios"%></li>
<%end%>
</ul>
<%= render :partial => 'teams/forms/team_players_input', :locals =>{ t: t}%>
<div class="modal-footer">
<button class="btn" type="button" id="boton">Cancelar</button>
<%=t.submit "Crear Team", :class => 'btn btn-primary', id: 'create_team_boton'%>
</div>
<%end%>
<%=form_tag team_players_input_teams_path, remote: true, id:'team_players_input', authenticity_token: true do%>
<%end%>
</div>
</div>
</div>
team_players_input controller action:
respond_to do |format|
format.js
end
team_players_input.js.erb:
$("#team-players-input").replaceWith("<%= escape_javascript(render(:partial => 'teams/forms/team_players_input', :locals => {t: t))%>");
_team_players_input.html.erb:
<div class="add_team_user" id="team-players-input">
<%if !@rendering.blank?%>
<%= t.fields_for :user do |u|%>
<ul class="team" id="add_team_players_list">
<div class="player">
<li>Player 1</li>
<ul class="team_player">
<li><%=u.input :name1, label: 'Nombre:'%></li>
<li><%=u.input :lastname1, label: 'Apellido:'%></li>
<li><%=u.input :rut1, label: 'Rut'%></li>
<li><%=u.input :nickname1, label: 'Nick:'%></li>
</ul>
</div>
</ul>
<%end%>
<%end%>
这是我的问题,需要捕获“t”模型才能在渲染文件中使用 fields_for,但会抛出下一个错误
ActionView::Template::Error (wrong number of arguments (0 for 1..2)):
app/views/teams/forms/_team_players_input.html.erb:3:in `_app_views_teams_forms__team_players_input_html_erb___3125175976749038336_69999593801700'
app/views/teams/team_players_input.js.erb:1:in `_app_views_teams_team_players_input_js_erb__1712103055993110209_69999599110300'
我如何将模型传递给渲染文件?请有人帮助我
最佳答案
要访问 team_players_input.js.erb
中的团队对象,您需要确保同一 Controller 中名为 team_players_input
的相应操作方法具有实例对象:@团队
。完成此操作后,您可以通过引用 @team
来访问 team_players_input.js.erb
中的 @team
对象。确保使用此 team_player_input
操作方法来呈现 js 请求。
此外,问题是 @team
对象如何在该操作方法中可用?基本上,你会从某个表单/按钮或 View 层的某些内容发出 js 请求。您需要在 js/ajax 请求中传递相关的 team_id
作为参数。稍后使用该 team_id
时,可以通过以下方式提供 @team
对象: @team = Team.find_by_id(params["team_id"].to_i )
编辑1:因此,您应该能够在此远程 js 调用中发送 team_id (可能类似于):
<%=form_tag team_players_input_teams_path, remote: true, id:'team_players_input', team_id: @team.id, authenticity_token: true do%>
然后在对应的action方法中:
team_players_input controller action:
@team = Team.find_by_id(params[:team_id].to_i) # this is to give you rough idea. You need to look at exact params and identity where team_id is in params hash
respond_to do |format|
format.js
end
..
完成这些后,您就可以在 team_players_input.js.erb
中访问 @team
:
$("#team-players-input").replaceWith("<%= escape_javascript(render(:partial => 'teams/forms/team_players_input', :locals => {t: @team))%>");
嗯,我想这太冗长了。但是,希望您发现它有帮助:)
关于javascript - 将每个内部的模型传递给 escape_javascript 以呈现表单,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38069673/
我有一个 aspx 应用程序。在每个 GET 中,服务器以包含除表格网格之外的所有内容的“基本”html 进行响应。 这个“网格信息”包含在页面中隐藏的输入类型(json 格式)中。 这是设计使然,无
阅读有关 iOS 中 UIViewControllers 更改的文档,我试图弄清楚呈现模态视图 Controller 之间的交互如何在自定义容器 View Controller 内工作。最终,我希望能
我正忙于编写自己的 JSF2 UIComponent 及其相关的渲染器。我所有的 UIComponent 都实现了 ClientBehaviorHolder。我不明白的是如何真正呈现 ClientBe
我正在开发一个使用UIPopoverController的应用程序,我在呈现该弹出窗口时遇到问题,我有一个添加在self.view上的UIView,并在该 View 上添加了一个表格 View ,该表
我有一个简单的应用程序,我想在用户首次登录应用程序时在其中显示一个 PageViewController。他们查看教程后,在下一次加载时不会显示 PageViewController。 但是我收到了以
我正在尝试制作一个小型的backbone.js 应用程序,但在事情的顺序上很挣扎。 在我的 html 文件中,标题中有两个脚本 block : jQuery(function(){
我有一个以模型为来源的表格: $form->setModel("test"); 在模型中,我们可以定义字段类型,例如:boolean 将在表单中制作复选框。 现在我们如何定义呈现为单选按钮的类型? 最
fabricJS 版本 2.2.3 测试 jsFiddle 我正在尝试使用 LabeledRect 子类,但我的问题是,每当我尝试从 JSON 加载它时,它都不会呈现,并且在控制台中也没有出现错误。请
在我的 Xaml 中,我定义了一个资源作为 vehicleDataInput,它提供一些文本框供用户输入数据。如果我没有为它定义一个 x:Key ,它将在我的应用程序中出现并按其应有的方式工作。问题是
我在 React 中创建了一个 Symbol 组件来轻松呈现 HTML Symbols像 euro 这样的名字将呈现 €(€) 或 sum 呈现 ∑(∑). 问题是,如果我只渲染 HTML 代码,我将
我尝试渲染一个 View ,该 View 工作正常,但似乎无法获得传递给它的模型对象。我不知道原因,因为根据所有手册和示例,这应该非常简单。 模型对象 class Race { def dis
我正在尝试为Grails项目添加一个简单功能,类似于youtube,它将允许用户喜欢/不喜欢文章。有一个非常原始的页面来显示带有喜欢的文章和一个使“喜欢”成为可能的 Controller 。 las,
我的应用程序中的第一个 ViewController 子类 UIImagePickerController 然后通过 didFinishPickingMediaWithInfo 回调,我执行以下操作:
我正在做一个简单的 redux/react todo 应用程序。我无法显示待办事项。我能够 console.log 数据,但无法显示它。我做错了什么? 我把文件分开了,这是我的app.js: impo
我正在尝试呈现一个导航 Controller ,它似乎可以工作并呈现导航 Controller 。但是,即使它有效,我仍然不断收到错误? 我的代码 let vc = storyboard.instan
我正在重新创建一个简单版本的 snapchat 应用程序,但遇到了一个恼人的小问题,我似乎无法找到解决办法。 我查看了一些答案,例如 this one但没有运气。 总体概念与 snapchat 用户单
我在呈现警报时遇到问题。我正在使用 UIAlertController。当用户按下提交按钮时,在应用程序执行某些操作时,需要立即显示“请稍候..”的警报。操作完成后,警报将消失。尽管应该在我开始执行操
我只是想用 Kinetic 渲染图像,但没有出现,也没有出现错误。 可以找到 fiddle here . 源代码: $( function() { var stage = new Kineti
我正在使用 Phantomjs 检查我的应用程序。我正在查看的页面包含很多组件,并且由 Angularjs 提供支持。我的测试服务器很慢。在 onLoadFinished 事件中,我使用渲染对网页进行
我有一个变量,它的字符串包含我所有的文档,如下所示: var string = " ReportHelloWorld"; 我想打开一个正确插入和显示此报告的新页面,但不知道如何操作。我该怎么办? 感谢
我是一名优秀的程序员,十分优秀!