2013-10-18 24 views
1

我有一個問題,回形針和軌道4 當上傳的圖像,我得到以下錯誤:軌道4回形針:缺少必需的attr_accessor

Image model missing required attr_accessor for 'pic_file_name' 

當添加推薦attr_accessors

attr_accessor :pic_file_name 
    attr_accessor :pic_content_type 
    attr_accessor :pic_file_size 
    attr_accessor :pic_updated_at 

該記錄已保存,但:pic列爲空,沒有上傳任何內容。

我也試過白名單:pic_file_name

private 
    # Use callbacks to share common setup or constraints between actions. 
    def set_image 
     @image = Image.find(params[:id]) 
    end 

    # Never trust parameters from the scary internet, only allow the white list through. 
    def image_params 
     params.require(:image).permit(:title, :pic, :pic_file_name) 
    end 

,但沒有成功。

任何想法這裏有什麼錯?

回答

3

我已經通過創建一個新的列

def change 
    add_column :images, :pic_file_name, :string 
    end 

可能是必要的軌道4級的應用解決了這一嘗試實現pic_file_name,不知道。 現在工作。

0

def pic_file_name 
pic 
end 

def pic_file_name(file_name) 
pic = file_name 
end 
+0

你的意思是模型? – DonMB