I have a form to add image url form, If user adds image url I want to download the image and save to local disk(home/documents/image)
I create image model and controller..
need help pls
in image model
class Image < ApplicationRecord
has_one_attached :image
require 'open-uri'
image = open('http://example.com/image.png')
IO.copy_stream(image, '~/home/Documents/Images/local_image.png')
end
in image controller
class ImagesController < ApplicationController
def index
@image = Image.new
end
end
in image/index.html.erb
<%= form_for(@image, url: images_path) do |f| %>
<%= f.text_field :image_url %>
<%=f.submit%>
<% end %>
but getting error
OpenURI::HTTPError in ImagesController#index 404 not found