Rails 3.1 一个表单上的多个对象 [英] Rails 3.1 multiple objects on one form

查看:42
本文介绍了Rails 3.1 一个表单上的多个对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我查看了很多关于将多个对象放在一个表单上的问题,但它们似乎已经过时了.

I've checked out a lot of questions for putting multiple objects on one form, but they seem to be out of date.

我有一堆用户对象:

  def index
    @users = User.all
    @user = current_user
  end

我需要在表单中编辑.他们都有将在表单上编辑的角色.表单以部分形式呈现,没有显示任何内容,只是管理表单"纯文本.

that I need to edit in a form. They all have roles which will be edited on the form. The form is rendered in a partial, and nothing shows up, just 'admin form' plaintext.

users/_admin.html.erb
admin form
<% form_for "user[]", :url => users_path do |f| %>
<ul>
  <li class="layout">
    <div class="header"><h2>Users</h2></div>
    <table>
      <thead>
          ...
      </thead>
      <tbody>
        <% @users.each do |user| %>
          <% puts "USER #{user}" %>
            <tr>
              <td><%= f.check_box(:editor) %></td>
              <td><%= f.check_box(:admin) %></td>
              <td><%= user.first_name %> <%= user.last_name %></td>
              <td><%= user.email %></td>
            </tr>
        <% end %>
      </tbody>
    </table>
  </li>
</ul>
<%= submit_tag "Save"%>
<% end %>

只呈现明文,但没有形式.关于如何解决它的任何想法?我已经尝试了这些帖子中的建议:one 两个 三个,但它们已经过时了.

Just the plaintext is rendered, but no form. Any ideas on how to fix it? I've tried the suggestions in these posts: one two three, but they're out of date.

谢谢.

推荐答案

你需要在 Rails 3.1 中使用 <%= .. %>:

You need to use <%= .. %> in Rails 3.1:

<%= form_for "user[]", :url => users_path do |f| %>

这篇关于Rails 3.1 一个表单上的多个对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆