Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5978339
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T21:30:05+00:00 2026-05-22T21:30:05+00:00

I am trying to create some image url upload. My file upload field works,

  • 0

I am trying to create some image url upload. My file upload field works, but when I submit a URL it submit and renders my indeks page and no image gets uploaded.

Here is my model:

class Konkurrancer < ActiveRecord::Base

    has_attached_file :photo,
                      :url  => "/public/images/billeder/photo/:id/:basename.:extension",
                      :path => ":rails_root/public/images/billeder/photo/:id/:basename.:extension"

    has_attached_file :photo2,
                      :url  => "/public/images/billeder/photo2/:id/:basename.:extension",
                      :path => ":rails_root/public/images/billeder/photo2/:id/:basename.:extension"

      attr_accessor :photo_url, :photo_url2

      def photo_url=(url) 
        return if url.blank?
        self.photo = RemoteUpload.new(url)
      end

      def photo_url2=(url) 
        return if url.blank?
        self.photo2 = RemoteUpload.new(url)
      end
end

My controller:

    def new
        @konkurrancer = Konkurrancer.new
        if !params[:konkurrancer].nil? && !params[:konkurrancer][:photo_url].blank?
        # user entered a photo url, use the url
        @konkurrancer.photo_remote_url = params[:konkurrancer][:photo_remote_url]
        elsif !params[:konkurrancer].nil? && !params[:konkurrancer][:photo]
         # use file upload  
        @konkurrancer.photo = params[:konkurrancer][:photo]
    end

    if !params[:konkurrancer].nil? && !params[:konkurrancer][:photo_url_2].blank?
      # user entered a photo url, use the url
      @konkurrancer.photo_remote_url = params[:konkurrancer][:photo_remote_url_2]
    elsif !params[:konkurrancer].nil? && !params[:konkurrancer][:photo]
      # use file upload
      @konkurrancer.photo2 = params[:konkurrancer][:photo2]
    end

        respond_to do |format|
          format.html # new.html.erb
          format.xml  { render :xml => @konkurrancer }
        end
      end

  # POST /konkurrancers
      # POST /konkurrancers.xml
      def create
        @konkurrancer = Konkurrancer.new(params[:konkurrancer])

        respond_to do |format|
          if @konkurrancer.save
            format.html { redirect_to(:admin_konkurrancers, :notice => 'Konkurrancer was successfully created.') }
            format.xml  { render :xml => :admin_konkurrancers, :status => :created, :location => @konkurrancer }
          else
            format.html { render :action => "new" }
            format.xml  { render :xml => @konkurrancer.errors, :status => :unprocessable_entity }
          end
        end
      end

My remote_upload.rb:

require 'open-uri'

# Make it always write to tempfiles, never StringIO
OpenURI::Buffer.module_eval {
  remove_const :StringMax
  const_set :StringMax, 0
}

class RemoteUpload 

  attr_reader :original_filename, :attachment_data

  def initialize(url) 
    # read remote data
    @attachment_data    = open(url)

    # determine filename
    path = self.attachment_data.base_uri.path

    # we need this attribute for compatibility to paperclip etc.
    @original_filename = File.basename(path).downcase
  end

  # redirect method calls to uploaded file (like size etc.)
  def method_missing(symbol, *args)
    if self.attachment_data.respond_to? symbol
      self.attachment_data.send symbol, *args
    else
      super
    end
  end

end

My view:

<%= simple_form_for [:admin, @konkurrancer], :html => { :multipart => true } do |f| %>
    <%= f.input :name, :label => 'Titel', :style => 'width:500;' %>
    <%= f.label :upload_125x125 %>
    <%= f.file_field :photo, :label => '125x125', :style => 'width:250;' %>
    <%= f.input :photo_url, :label => 'URL 125x125', :style => 'width:250;' %>
    <%= f.label :upload_460x60 %>
    <%= f.file_field :photo2, :label => '460x58', :style => 'width:250;' %>
    <%= f.input :photo_url2, :label => 'URL 460x58', :style => 'width:250;' %>
    <%= f.button :submit, :value => 'Create konkurrence' %>
<% end %>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T21:30:06+00:00Added an answer on May 22, 2026 at 9:30 pm

    I was in the middle of writing a pretty through response, and then I found someone already wrote the same thing!!

    Here you go: http://trevorturk.com/2008/12/11/easy-upload-via-url-with-paperclip/

    This should be exactly what you are looking for. If you stumble, let me know.

    Good luck

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to create images hyperlinked to some URL's and hyperlinks donot seem
I'm trying to create a background position change with animation. but for some reason
I'm trying to create some kind of callback code which gets executed after an
I am trying to create a page that lets a user delete an image
I'm trying to create some HtmlHelper extensions and ran into a bit of a
I am trying to create some reusable components in Silverlight2 . The difficulty comes
I am trying to create some charts of data (eg http://www.amibroker.com/ ). Is there
I am trying to create some rules and facts on a certain situation. The
I am trying to create some global variables in a firefox extension. In my
I am trying to create some script variables in T-SQL as follows: /* Deployment

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.