2012-11-11 124 views
0

我得到這個錯誤,當我用新的行動形式上傳photos.I試圖獲得多個照片上傳視圖指3線。照片被貼在物品上和項目被添加到人頭。該初步認識代碼:未定義的方法`MODEL_NAME」的NilClass:類中的Rails 3

-# new view 
%h1 Upload item pictures 
= form_for(@poll, :html => {:multipart => true }) do |f| 
    - @poll.errors.full_messages.each do |msg| 
    %p = msg 
    %fieldset 
    = f.label :title 
    = f.text_field :title 
    %fieldset 
    Pending Attachments: (Max of #{Item::Max_Attachments}) each under #{Item::Max_Attachment_Size/1.megabyte} MB) 
    - if @poll.items.count >= Item::Max_Attachments 
     <input id="newfile_data" type="file" disabled /> 
    - else 
     %input{:id => "newfile_data", :type => "file"} 
    #attachment_list 
     %ul{:id => "pending_files"} 
    %fieldset 
    = f.submit "Create" 

class PollsController < ApplicationController 
    # POST /polls 
    def create 
    @poll = Poll.new(params[:poll]) 
    process_file_uploads(@poll) 
    if @poll.save 
     flash[:notice] = 'poll was successfully created.' 
     redirect_to(@poll) 
    else 
     render :action => "new" 
    end 
    end 
    private 
    def process_file_uploads(poll) 
    i = 0 
    while params[:attachment]['file_'+i.to_s] != "" && !params[:attachment]['file_'+i.to_s].nil? 
     poll.items.build(:photo => params[:attachment]['file_'+i.to_s]) 
     i += 1 
    end 
    end 
end 

class Poll < ActiveRecord::Base 
    has_many :items, :dependent => :destroy 
    accepts_nested_attributes_for :items 
end 

是否有什麼錯我的代碼?謝謝!

回答

0

我知道了。只需要在polls_controller定義新的像

def new 
    @poll = Poll.new 
end 

和它的作品!

相關問題