Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

simple_form_for fails with "can't write unknown attribute `builder'"

I have a Post model with a one-to-many relationship with a Comments model. I'm using simple_form in a partial to create some quick forms (specifically, for the comment model) for my user interface:

<%= 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 %>

However, Rails fails with the following error: can't write unknown attribute 'builder' and the stack trace pointing to the first line (<%= simple_form_for(@post, Comment.new) do |f| %>).

Where does this builder attribute come from and how can I make this work? Thanks.

like image 456
Ryan Morrison Avatar asked Jul 02 '13 23:07

Ryan Morrison


1 Answers

I guess you use nested resources. If so, AFAIK, you should pass an array to simple_form_for method as first parameter (responsible for setting the proper form URL):

<%= simple_form_for [@post, Comment.new] do |f| %>
like image 51
Marek Lipka Avatar answered Sep 28 '22 15:09

Marek Lipka