2014-02-19 33 views
1

我是RoR的新手,所以這可能是大部分人的5分鐘任務。用RoR上傳多個圖片

我想用回形針上傳多個圖像 - 最初我設置了應用程序以使用回形針上傳單個圖像。我現在已經添加了一個單獨的資產表,併爲關係使用了「嵌套屬性」,但失去了錯誤。

確定這是一件非常明顯的事情,最有可能通過更改上傳單個圖像和爲多個圖像引入單獨的資產表來實現。

該應用程序保存在這裏。 https://github.com/KiwiChristy/Pinteresting

由於

+1

努力研究網絡? – Nithin

回答

0

#app/views/images/new.html.erb 
<%= form_for @image do |f| %> 
    <%= f.file_field :image %> 
    <%= f.file_field :image %> 
    <%= f.file_field :image %> 
    <%= f.submit %> 
<% end %> 

控制器

#app/controllers/images_controller.rb 
    def new 
     @image = Image.new 
    end 

    def create 
     @image = Image.new(image_params) 
    end 

    private 

    def image_params 
     params.require(:image).permit(image: []) 
    end 

模型

#app/models/image.rb 
Class Image < ActiveRecord::Base 
    has_attached_file :image 
end 

好資源:https://gist.github.com/patrickberkeley/33011