Question

I'm looking to have a html table where every row is it's own form.

For the model Post, I would instantiate a collection in the controller with @posts = Post.all

In the view I would loop through those with .each and render a form for each instance (stripped from erb tags for clarity):

<tbody>
  @posts.each do |post|
    <tr>
      form_for(post) do |f|
        <td>f.text_field :title</td>
        <td>f.text_area  :content</td>
        <td>f.submit</td>
      end
    </tr>
  end
</tbody>

I get an error though about no matching route and "missing required keys: [:id]".

Is post not an instance object or what am I doing wrong here?

Was it helpful?

Solution

missing required keys [:id] suggests to me that either the form cannot access post's id or its parent's id, if it's nested.

Try to define the url explicitly and with helpers.

form_for(post, :url => post_path(post))

Or if it's nested:

form_for(post, :url => topic_post_path(post.topic, post))
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top