conpill
conpill

Reputation: 147

Paperclip error rails 3

So I have been trying to follow some paperclip tutorials and adjusting them to rails 3. I follow the steps and got an error once I started to add the code needed for the _form and show.htm.erb files. This is the error I get.

Error Message:

ActionView::Template::Error (undefined method `label' for nil:NilClass):
11:     </div>
12:   <% end %>
13: <div class="field">
14: <%= form.label :photo, "Photo" %>  
15:       <%= form.file_field :photo %>  
16: </div>
17:   <div class="field">

Form:

       <%= form_for @user, :html => { :multipart => true } do |f| %>
     <% if @user.errors.any? %>
       <div id="error_explanation">
         <%= pluralize(@user.errors.count, "error") %> prohibited this user from being saved:

          <ul>
      <% @user.errors.full_messages.each do |msg| %>
       <li><%= msg %></li>
     <% end %>
       </ul>
    <div>
  <% end %>
<div class="field">
 <%= form.label :photo, "Photo" %>  
      <%= form.file_field :photo %>  
</div>
  <div class="field">
    <%= f.label :name %><br />
   <%= f.text_field :name %>
  </div>
   <div class="field">
    <%= f.label :password %><br />
    <%= f.text_field :password %>
 </div>
  <div class="actions">
   <%= f.submit %>
 </div>
<% end %>`

Upvotes: 0

Views: 595

Answers (1)

user229044
user229044

Reputation: 239230

form.label doesn't make sense, since you're calling your form variable f inside your block, with the line form_for ... do |f|.

You need to use f.label etc.

Upvotes: 4

Related Questions