- xml - AJAX/Jquery XML 解析
- 具有多重继承的 XML 模式
- .net - 枚举序列化 Json 与 XML
- XML 简单类型、简单内容、复杂类型、复杂内容
我在使用简单的 bool 复选框更新记录列表时遇到了严重的问题。
我需要能够列出我的“事件”并在日期可用时选中或取消选中它们。我想在一种形式上做到这一点。我知道这是可能的,但在无法正常工作后我终于来到了这里。
当我提交表单时,它遵循正确的 if: redirect 路径,就好像更新已成功...但记录保持不变并且 updated_at 也保持未链接。
我试过这些信息来源: http://railscasts.com/episodes/52-update-through-checkboxes http://discuss.codeschool.io/t/surviving-apis-with-rails-posting-multiple-records/4776/4 http://railscasts.com/episodes/165-edit-multiple-revised
这是我的位置
路线.rb
resources :events do
collection do
put :verified
post :make_events
end
end
events_controller.rb
def verified
if Event.where(id: params[:event_ids]).update_all(available: true)
redirect_to step2_path(:pid => @project.id, :u => current_user.id)
else
redirect_to show_events_path(:pid => @project.id, :u => current_user.id)
end
end
显示.html.erb
<%= form_tag verified_events_path(:pid => @project.id ), method: :put do %>
<table class="table-event-dates">
<thead>
<tr>
<th> </th>
<th> </th>
</tr>
</thead>
<tbody>
<tr><% @these_events.each do |event| %>
<td><%= check_box_tag "event_id[]", event.id, :value => event.available %></td>
<td><label> <%= event.date.strftime("%A, %b. %d %G") %></label></td>
</tr>
</tbody>
<% end %>
</table>
</div><br><!-- panel-body -->
<div class="panel-footer2">
<div class="row">
<%= submit_tag 'Verify Dates', :class => 'btn btn-green btn-lg btn-block' %>
<% end %>
我已经坚持了一段时间。
我发布了一个类似的问题,但修复与错误无关,也没有解决错误……但是,它确实解决了另一个错误。很抱歉发了两次,但这似乎是我同一个项目中的一个不同问题。
update multiple records in one form using checkboxes / wrong number of aruguments rails 4
最佳答案
所以我的问题的关键原来是没有列出 bool 变量和我必须为未选中的复选框指定一个值的组合。
这救了我:
Controller :
def verfied
Event.where(id: params[:event_ids]).update_all({:available => true})
Event.where.not(id: params[:event_ids]).update_all({:available => false})
return redirect_to step2_path(:pid => @project.id, :id => @project.id, :u => current_user.id, :t => @project.template_id)
else
redirect_to event_edit_path(:pid => project_id, :u => current_user.id)
end
这是我的表单的最终代码:
<div class="form-wrap">
<%= form_tag verified_events_path(:pid => @project.id ), method: :put do %>
<table class="table-event-dates">
<thead>
<tr>
<th> </th>
<th> </th>
</tr>
</thead>
<tbody>
<tr><% @these_events.each do |event| %>
<td><%= check_box_tag "event_ids[]", event.id, event.available %><%= hidden_field_tag :updated_at, Time.now %></td>
<td><label> <%= event.date.strftime("%A, %b. %d %G") %></label></td>
</tr>
</tbody>
<% end %>
</table>
</div><br><!-- panel-body -->
<div class="panel-footer2">
<div class="row">
<%= submit_tag 'Verify Dates', :class => 'btn btn-green btn-lg btn-block' %>
</div>
</div>
</div><!-- panel -->
</div><!-- col-md-6 --><!-- col-md-6 -->
<% end %>
关于ruby-on-rails - 无法以充满 check_box_tag 字段的形式获取 Update_all 在 Rails 4 中工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25315823/
这是一个新手理论问题 - 我刚刚开始使用 Python 并研究 Django 和 orm。问题:如果我开发我的对象并通过额外的开发修改基础对象结构、继承等 - Django 的 ORM 解决方案会自动
我正在使用带有服务器端处理器的 JavaScript 表单,并且我希望能够让表单根据下拉列表转到不同的电子邮件。我已经根据其他表格尽了最大努力,但似乎无法通过电子邮件。我已在电子邮件地址的选项标签下添
一个简单的问题:给定定义,(来自 Haskell SOE) do x — el; el\ ...; en => el »= \x — do e2\ ...; en 和: do let d
我是 Angular 5 的新手。我目前正在研究 Angular Reactive 表单。我有一个下面的 JSON 结构,我需要在从 FORM 获取值后发回 REST API。 JSON 结构: {
我是 Angular 5 的新手。我目前正在研究 Angular Reactive 表单。我有一个下面的 JSON 结构,我需要在从 FORM 获取值后发回 REST API。 JSON 结构: {
我有一个类型(称之为 A),我想创建一个 A -> A、A -> A -> A、A -> A -> A -> ... 等类型的函数的类型类.这不起作用: {-# LANGUAGE FlexibleIn
我正在使用 java 线程同时管理多个 (3) 程序。1 用于 Java swing 表单(绘制 UI 以进行输入),1 用于在系统托盘上设置图标(从 UI 获取输入后立即启动),1 用于处理输入并将
在当前的元素中,我在表单中遇到了一个问题。表单中标签的字体大小可能大于默认值。如果我把它举起来,那么右边的输入必须垂直居中。 我查看了 Bootstrap 和 Foundation,但都没有解决这个问
为了好玩,我使用了一段从 friend 那里得到的代码,并尝试创建一个包含用户名和密码的登录字段,但我很难获得单词旁边的字段。 username 这个词和你输入的框之间有很大的差距。密码也是如此。 这
我的表单中有一个嵌套的控制组,我想访问它们的表单状态值(如原始和有效)以动态显示验证错误。 是这样动态构建的 controlMap['password'] = this.password; contr
发送后我试图重置我的表单,但只有值设置为空。 component.html {{note.value?.length || 0}}/10
我正在尝试自定义 Stripe 结帐表单,但我不知道如何添加输入。我想添加“电话号码”和“姓名”以创建费用和客户。你知道我该怎么做吗? 这是我应该自定义的代码。 最佳答案 您将无法使用
所以我有这个需求,我想以表格的形式提交一个由五个记录组成的表单。这就是它的样子表: 这是对应的代码: Section Q.No Question
我有一个使用 react 形式和输入文本的情况。 我需要: 当用户输入时,根据输入的内容建议一个列表(我使用的是 ngx bootstrap typeahead); 仅当用户失去输入焦点时才验证输入字
我希望重构我的 Angular 项目中的大量组件,以具有强类型的 FormGroups、FormArrays 和 FormControls。 我只是在寻找一种实现强类型 react 形式的好方法。任何
我有事件表格: 'horizontal', 'fieldConfig' => [ 'template' => "{input}\n{hint}\n{error}",
是否有关于如何实现多选和响应式表单的示例? 我正在尝试在 multiselect-dropdown 上设置所选项目(从数据库中检索),它会更新显示的项目( View ),但会引发以下错误: core.
我想在表单中添加按钮以动态添加输入。但是我发现,如果我在表单中添加了一个仅记录到控制台的按钮(并且当我尝试添加输入时),它将记录日志,然后表单中断。我的Electron应用程序的前端窗口崩溃(不退出但
我有一个这样的表格 此表单位于指令内: angular.module('crowdcoreApp').directive('investorForm',function(){
我在 angularjs Controller 中调用的 $mdDialog 中有一个表单,如下所示: actions-controller.js function callForm() {
我是一名优秀的程序员,十分优秀!