Rails保留现有值并向数组添加更多值

时间:2018-03-13 10:19:57

标签: ruby-on-rails ruby

我试图保留数组<!DOCTYPE html> <html> <body> <button class="button button1" onclick="PlusPage()">Next Page </button> <button class="button button1" onclick="RemPage()">Previous Page </button> <br><br> <img id="page" src="https://github.com/sudface/ps8/raw/master/1.png" alt=""> <br>The below textbox should alter the page. but instead, the whole thing stops functioning. <input id="someInput" type="text"> <input type="button" value="Go to Page" onClick="doStuff()"> </body> </html>的现有值,并将@account.images的值添加到数组中,如下所示:

new_images

这就是我在强大的def add_more_images(new_images) @account = Account.find(params[:id]) @images = [@account.images] @images += [new_images] @account.assign_attributes({ :images => @images }) end

中所拥有的

这是我从`@ account.images:

获得的

{images: []}

这是我从[#<AttachmentUploader:0x007f98699482f8 @model=#<Account id: 1, business_name: "Example Account", business_description: "There are many variations of passages of Lorem Ips...", web_site: "www.example.com", phone_number: "", street: "", zip_code: "6021", country: "", store_id: 1, city: "", state: "", created_at: "2018-03-04 14:39:23", updated_at: "2018-03-13 09:19:30", images: [nil, nil, nil, "image8.jpg"]>, @mounted_as=:images, @storage=#<CarrierWave::Storage::File:0x007f9869948258 @uploader=#<AttachmentUploader:0x007f98699482f8 ...>>, @file=#<CarrierWave::SanitizedFile:0x007f986a1f3ce0 @file="/Users/RubymineProjects/pinsle/public/uploads/account/images/1/image8.jpg", @original_filename=nil, @content_type=nil>, @versions={:thumb=>#<AttachmentUploader::Uploader70146304658160:0x007f986a1f3c90 @model=#<Account id: 1, business_name: "Example Account", business_description: "There are many variations of passages of Lorem Ips...", web_site: "www.example.com", phone_number: "2349875678", street: "", zip_code: "", country: "", store_id: 1, city: "", state: "", created_at: "2018-03-04 14:39:23", updated_at: "2018-03-13 09:19:30", images: [nil, nil, nil, "image8.jpg"]>, @mounted_as=:images, @parent_version=#<AttachmentUploader:0x007f98699482f8 ...>, @storage=#<CarrierWave::Storage::File:0x007f986a1f3bc8 @uploader=#<AttachmentUploader::Uploader70146304658160:0x007f986a1f3c90 ...>>, @file=#<CarrierWave::SanitizedFile:0x007f986a1f36a0 @file="/Users/RubymineProjects/pinsle/public/uploads/account/images/1/thumb_image8.jpg", @original_filename=nil, @content_type=nil>, @versions={}>, :mini=>#<AttachmentUploader::Uploader70146304645520:0x007f986a1f3c68 @model=#<Account id: 1, business_name: "Example Account", business_description: "There are many variations of passages of Lorem Ips...", web_site: "www.example.com", phone_number: "2349875678", street: "", zip_code: "", country: "", store_id: 1, city: "", state: "", created_at: "2018-03-04 14:39:23", updated_at: "2018-03-13 09:19:30", images: [nil, nil, nil, "image8.jpg"]>, @mounted_as=:images, @parent_version=#<AttachmentUploader:0x007f98699482f8 ...>, @storage=#<CarrierWave::Storage::File:0x007f986a1f35d8 @uploader=#<AttachmentUploader::Uploader70146304645520:0x007f986a1f3c68 ...>>, @file=#<CarrierWave::SanitizedFile:0x007f986a1f30b0 @file="/Users/RubymineProjects/pinsle/public/uploads/account/images/1/mini_image8.jpg", @original_filename=nil, @content_type=nil>, @versions={}>}>]得到的:

new_images

这是我在这一行[#<ActionDispatch::Http::UploadedFile:0x007f986a2096a8 @tempfile=#<Tempfile:/var/folders/hq/pr4rt14n7s31v3f6292wtjm00000gn/T/RackMultipart20180313-2377-yox8g6.jpg>, @original_filename="image1.jpg", @content_type="image/jpeg", @headers="Content-Disposition: form-data; name=\"account[images][]\"; filename=\"image1.jpg\"\r\nContent-Type: image/jpeg\r\n">]

上得到的错误no implicit conversion of nil into String

我在这里做错了什么以及如何使这项工作成功?

1 个答案:

答案 0 :(得分:0)

你必须使用这样的东西:

$array = ["1", "hello", "1", "world", "hello"];