我有一个Post模型,它与Comments模型有一对多的关系。我在部分使用simple_form为我的用户界面创建了一些快速表单(特别是对于评论模型):
<%= simple_form_for(@post, Comment.new) do |f| %>
<%= f.error_notification %>
<div class="form-inputs">
<%= f.input :comment, :input_html => {:rows => 20, :class => 'span12'} %>
</div>
<div class="form-actions">
<%= f.button :submit %>
</div>
<% end %>
但是,Rails失败并出现以下错误:can't write unknown attribute 'builder'
并且堆栈跟踪指向第一行(<%= simple_form_for(@post, Comment.new) do |f| %>
)。
此构建器属性来自何处以及如何使其工作?感谢。
答案 0 :(得分:14)
我猜你使用nested resources
。如果是这样,AFAIK,您应该将数组作为第一个参数传递给simple_form_for
方法(负责设置正确的表单URL):
<%= simple_form_for [@post, Comment.new] do |f| %>