Gem simple_form 表单提交错误

sanvi · January 17, 2012 · Last by jonny replied at February 04, 2012 · 2618 hits

我有一个 form 表单,用的是 simple_form

<%= simple_form_for([:admin, @category], :wrapper => :inline) do |f| %>
  <% if @category.errors.any? %>
    <div id="error_explanation">
      <h2><%= pluralize(@category.errors.count, "error") %> prohibited this category from being saved:</h2>
      <ul>
      <% @category.errors.full_messages.each do |msg| %>
        <li><%= msg %></li>
      <% end %>
      </ul>
    </div>
  <% end %>

 <%= f.input :name %>
 <%= f.input :parent,  :collection => Category.all%>

  <div class="actions">
     <%= f.button :submit %>
  </div>
<% end %>

但事提交的时候

ActiveRecord::AssociationTypeMismatch in Admin::CategoriesController#create
Category(#70187922823040) expected, got String(#70187915399620)

Category expected, got String 不是都告诉你了么,需要一个 category,但是得到的是 string

= f.input :parent_id, :as => :select, :collection => Category.xx.map{|x| [x.name, x.id]}

#2 楼 @vkill 谢谢,请问哪可以查到这方面的文档

You need to Sign in before reply, if you don't have an account, please Sign up first.