ruby - rails accessing ActionDispatch error -


i trying change data on request before save

request

{"image"=>{"picture"=>[#<actiondispatch::http::uploadedfile:0x10c865af8 @tempfile=#<file:/var/folders/bx/6z1z5yks56j40v15n43tjh1c0000gn/t/rackmultipart20130404-53101-1p7gv92-0>,  @headers="content-disposition: form-data; name=\"image[picture][]\"; filename=\"ata.png\"\r\ncontent-type: image/png\r\n",  @content_type="image/png",  @original_filename="ata.png">,  #<actiondispatch::http::uploadedfile:0x10c865ad0 @tempfile=#<file:/var/folders/bx/6z1z5yks56j40v15n43tjh1c0000gn/t/rackmultipart20130404-53101-992qy5-0>,  @headers="content-disposition: form-data; name=\"image[picture][]\"; filename=\"ata@2x.png\"\r\ncontent-type: image/png\r\n",  @content_type="image/png",  @original_filename="ata@2x.png">],  "album_id"=>"10"},  "authenticity_token"=>"00/bntiry5oiggsxzewiv2fccfiirhsxutg/uep32h8=",  "commit"=>"submit",  "utf8"=>"✓",  "album_id"=>"10"} 

controller

def create     @album = album.find(params[:album_id])         p = image.find(params[:image][:picture])         p.each |pic|             @image = @album.images.new(params[:image][p => :picture])         end         if @image.save             flash[:notice] = "successfully added image!"             redirect_to [:admin, @album, :images]         else             flash[:notice] = "failed"         end     end 

why code produce error? if error resolved, code work create new image object every :picture array in hash?

i guess it's simple typo:

p.each |pic|   @image = @album.images.new(params[:image][p => :picture]) end 

you do |pic| don't use pic anywhere.


Comments

Popular posts from this blog

monitor web browser programmatically in Android? -

Shrink a YouTube video to responsive width -

wpf - PdfWriter.GetInstance throws System.NullReferenceException -