Using partials

On the left hand side of my page there is a list of documents that the
user has already created. And a form to create/edit documents.

| list of documents| Edit/Create documents|
| | |
| | |
I am trying to do the following

  1. Show form for creating a new document when the page first loads.And
    on button click reload the page with the updated list and the document
    newly created.

  2. When user clicks on one of the existing documents I want to update
    the form to display the details of the document.

I was thinking that partials would be the way to do this.

I have part of (1) done. Now I 'm trying to load the details of the
existing documents.

Any suggestions on how to fix the following error and secondly reload
page when a new document is created.

undefined local variable or method `document’ for
#<#Class:0x007fb10b926c60:0x007fb109fad478>
Extracted source (around line #1):

1: <%= form_for document do |f| %>
2:


3: <%= f.label :name %>

4: <%= f.text_field :name %>
Index.html.erb
<%= search_field(:user, :document) %>

<% @documents.each do |document| %>

  • <%= link_to document.name, edit_document_path(document.id)
    %>

  • <% end %>

    <%= link_to ‘New Document’, new_document_path %>

    <%= render :partial => "form", :locals => { :document => Document.new } %>
    _form.html.erb

    <%= form_for document do |f| %>

    <%= f.label :name %>
    <%= f.text_field :name %>
    <%= f.label :notes %>
    <%= f.text_area :notes %>
    <%= f.submit %>
    <% end %>

    On 30 March 2013 20:59, Jay notReq [email protected] wrote:

    newly created.
    page when a new document is created.
    I would ask one question at a time, otherwise the thread will get side
    tracked. First fix the error.


    <%= link_to ‘New Document’, new_document_path %>

    <%= render :partial => "form", :locals => { :document => Document.new } %>

    Are you sure you have not got another call to the form partial
    somewhere else, and have forgotten the locals specification there?

    If not then have a look at the Rails Guide on debugging which will
    show you techniques that you can use to debug the code.

    Colin