Submitting partial data forms from other controllers

I have several shared parts that I can display from any controller, but I have few problems displaying partial data from another controller. I want to be able to add notes to my contacts.

In my contacts /show.html.erb I have

<% render :partial => "notes/form", :note => Note.new %>

In my notes /_form.html.erb I have

<%= form_for @note do |f| %>
  <%= render 'shared/error_messages', :object => f.object %>
  <p>
    <%= f.label :content %><br />
    <%= f.text_field :content %>
  </p>
  <p>
    <%= f.label :contact_id %><br />
    <%= f.number_field :contact_id %>
  </p>
  <p><%= f.submit %></p>
<% end %>

However, I get the error message:

Display / Applications / Rails / apps / saas31 / app / views / notes / _form.html.erb, where line # 1 is raised:

undefined method `` model_name '' for NilClass: Class

Extracted source (around line # 1):

1: <% = form_for @note do | f | %> 2: <% = render 'shared / error_messages' ,: object => f.object%>

, , , - , . - ?

+5
2

locals.

<% render :partial => "notes/form", :locals => {:note => Note.new} %>

3.4.4 .

, :

<%= form_for @note do |f| %>

<%= form_for note do |f| %>

, :

<% render :partial => "notes/form", :locals => {:note => @note} %>
+17

, . , , - :)

_form.html.erb, /users/new. /layouts/application.html.erb, .

(new_user) application_helper.rb. :

def new_user
  User.new    
end

application.html.erb :

<%= render :partial => 'users/form', :locals => {:user => new_user} %>
+2

All Articles