2012-11-24 6 views
0

나는 railcasts.com에서 제안한 여러 파일 업로드를 시도하고 있습니다. Jquery File Upload. 빈 아이콘 Carrierwave 파일 업로드

  • 파이어 폭스 : 나는, 그러나 그것은 아무 것도 볼 수없는됩니다 내가 서버를 새로 고치는 것이 매번 것 그리고 다음 브라우저에서 내가이

    • 구글에서 얻을, 테스트를 수행 한 텍스트 "/ 자산/
    . imageid 여기

    내 코드 업 로더

    를 :

    아무것도 내가 업 로더 공공/업로드 될 수 내 사진을 원하는 내 폴더 /에 업로드 할 것 없다

    class AimageUploader < CarrierWave::Uploader::Base 
    
        include CarrierWave::RMagick 
        include Sprockets::Helpers::RailsHelper 
        include Sprockets::Helpers::IsolatedHelper 
        storage :file 
        def store_dir 
        "uploads/#{model.id}" 
        end 
        version :thumb do 
        process :resize_to_fill => [200, 200] 
        end 
        def extension_white_list 
        %w(jpg jpeg gif png) 
        end 
    end 
    

    보기

    <div><%= image_tag(ad.aimage_url(:thumb)) %></div> 
    

    나는 단계를 놓친 건가?

    모델

    # == Schema Information 
    # 
    # Table name: ads 
    # 
    # id    :integer   not null, primary key 
    # name    :string(255) 
    # aimage   :string(255) 
    # created_at  :datetime   not null 
    # updated_at  :datetime   not null 
    # advertisement_id :integer 
    # 
    
    class Ad < ActiveRecord::Base 
        attr_accessible :aimage, :advertisement_id, :name 
        mount_uploader :aimage, AimageUploader 
    end 
    

    보기 index.html.erb

    <% @ads.each do |ad| %> 
        <div><%= ad.name %></div> 
        <%= image_tag(ad.aimage_url(:thumb)) if ad.aimage? %> 
        <div> 
        <%= link_to 'Show', ad %> 
        <%= link_to 'Edit', edit_ad_path(ad) %> 
        <%= link_to 'Destroy', ad, method: :delete, data: { confirm: 'Are you sure?' } %> 
        </div> 
    <% end %> 
    <br /> 
    
    <%= form_for Ad.new do |f| %> 
        <div><%= f.label :aimage, "Upload advertisement:" %></div> 
        <div><%= f.file_field :aimage, multiple: true, name: "advertisement[aimage]" %></div> 
    <% end %> 
    

    컨트롤러

    class AdsController < ApplicationController 
        def index 
        @ads = Ad.all 
        end 
        def show 
        @ad = Ad.find(params[:id]) 
        end 
        def new 
        @ad = Ad.new 
        end 
        def edit 
        @ad = Ad.find(params[:id]) 
        end 
        def create 
        @ad = Ad.create(params[:ad]) 
        if @ad.save 
         flash[:notice] = "Successfully created advertisement." 
         redirect_to root_url 
        else 
         render :action => 'new' 
        end 
        end 
        def destroy 
        @ad = Ad.find(params[:id]) 
        @ad.destroy 
        end 
    end 
    

    자바 스크립트 ads.js.coffee

    jQuery -> 
        $('#new_ad').fileupload() 
    

    내게는 모두 좋은 것처럼 보입니다!

    class User < ActiveRecord::Base 
        has_many :images 
    end 
    

    당신은 별도의 image_controller을 가질 수 있습니다

    class Image < ActiveRecord::Base 
        has_attached_file :file 
    end 
    

    여러 이미지를해야합니다 사용자 모델을 가정 해 봅시다 :

  • 답변

    1

    Is 귀하의 업 로더가 귀하의 모델에 장착 되었습니까? 되지 않은 경우,이

    mount_uploader :image, AimageUploader 
    

    을 시도하고이 링크는 질문에 대답 수 있지만 또한,보기에, 여러 옵션

    <%= f.file_field :image, multiple: true, name: "model_name[image]" %> 
    
    +0

    나는 내 코드를 보여줄 것이다! – Jseb

    0

    나는 다음과 같이 모델이라는 이미지를 만들 paperclip

    를 사용하는 것이 좋습니다 파일 업로드를 처리 할 수 ​​있습니다.

    +1

    을 설정, 그것은 여기에 해답의 본질적인 부분을 포함하는 것이 좋습니다 및 참조 용 링크를 제공하십시오. 링크 된 페이지가 변경되면 링크 전용 답변이 유효하지 않게 될 수 있습니다. – Nikhil

    +0

    클립 클립이있는 것은 다중 파일 업로드를 허용하지 않으므로 carrierwave로 변경합니다. – Jseb

    +0

    간단한 JQuery를 사용하여 여러 파일 업로드를 허용 할 수 있습니다. – dealer

    관련 문제