title: How can I download image from URL in rails using and save it to local disk(computer)?
body: <p>I have a form to add image url <a href="https://i.stack.imgur.com/zHpJ0.png" rel="noreferrer">form</a>,
  If user adds image url I want to download the image and save to local disk(home/documents/image) </p>
  
  <p>I create image model and controller..</p>
  
  <p>need help pls</p>
  
  <p>in image model</p>
  
  <pre><code>class Image &lt; 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
  </code></pre>
  
  <p>in image controller</p>
  
  <pre><code>class ImagesController &lt; ApplicationController 
  
      def index
        @image = Image.new
      end
  
  end
  </code></pre>
  
  <p>in image/index.html.erb</p>
  
  <pre><code>&lt;%= form_for(@image, url: images_path) do |f| %&gt;
    &lt;%= f.text_field :image_url %&gt;
    &lt;%=f.submit%&gt;
  &lt;% end %&gt;
  </code></pre>
  
  <p>but getting error</p>
  
  <pre><code>OpenURI::HTTPError in ImagesController#index 404 not found
  </code></pre>