I have the following form partial (contacts/_form.html.erb)
<%= semantic_form_for [@contact.user, @contact], :remote => true do |f| %>
<% f.inputs do %>
<%= f.input :firstname, :label => 'First Name' %>
<%= f.input :lastname, :label => 'Last Name' %>
<%= f.input :email, :label => 'Email' %>
<%= f.input :groups, :collection => @user.groups, :as => :check_boxes, :label => 'Groups' %>
<%= f.input :notes, :input_html => { :class => 'autogrow', :rows => 10, :cols => 50, :maxlength => 10 }, :label => 'Notes' %>
<% end %>
<%= f.buttons do %>
<% if ["edit", "update"].include? params[:action] %>
<%= button_submit_tag raw("Update Contact →") %>
<% else %>
<%= button_submit_tag raw("Create Contact →") %>
<% end %>
<% end %>
<% end %>
I am trying to render it from contacts/index.html.erb
<%= render :partial => 'form'%>
But i get the error…
undefined method `user' for nil:NilClass
What was happening was a stupid mistake.
I was having CANCAN load and authorize the resource, then i was specifying the @contacts = whatever for my index view, and it was screwing cancan up and it wasn’t auto generating the instance variables for that action anymore.
Either way the fix was writing it out instead of letting cancan auto-generate it…