2016-12-23 13 views
1

私はレールでform_forを使用していくつかのパラメータを渡そうとしていますが、コントローラに次のようにアクセスできるようにするにはどうすればいいですか?params[:image]?私のform_forタグの開始は、次のようになります。ruby​​ on railsでのパラメータの名前付けに使用するフォーム番号

<%= form_for(@image, as: :image, url: create_image_path(current_user), html: { multipart: true }, method: :post) do |f| %> 
+1

[デフォルトの 'file_field'](http://guides.rubyonrails.org/fo rm_helpers.html#uploading-files)helpers?もしそうなら、どのようにあなたの完全なコードを見て、どのようなエラー/問題が見えて、あなたは何を期待していますか? –

+0

私の解決策があなたを助けないかどうか教えてください。 –

答えて

0

私はあなたの例を与えることができcarrierwave

宝石がcarrierwave

rails g model Resume attachment:string 

rails g uploader attachment 

をインストールwtih **モデル、コントローラとビューでこれを追加**

class Resume < ActiveRecord::Base 
    mount_uploader :attachment, AttachmentUploader # Tells rails to use this uploader for this model. 

end 



class ResumesController < ApplicationController 
    def index 
     @resumes = Resume.all 
    end 

    def new 
     @resume = Resume.new 
    end 

    def create 
     @resume = Resume.new(resume_params) 

     if @resume.save 
     redirect_to resumes_path, notice: "The resume #{@resume.name} has been uploaded." 
     else 
     render "new" 
     end 

    end 

    def destroy 
     @resume = Resume.find(params[:id]) 
     @resume.destroy 
     redirect_to resumes_path, notice: "The resume #{@resume.name} has been deleted." 
    end 

    private 
     def resume_params 
     params.require(:resume).permit(:attachment) 
    end 

end 


<div class = "well"> 
    <%= form_for @resume, html: { multipart: true } do |f| %> 
     <%= f.file_field :attachment %> 
     <%= f.submit "Save", class: "btn btn-primary" %> 
    <% end %> 
</div> 
関連する問題