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 7187593
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T18:52:52+00:00 2026-05-28T18:52:52+00:00

I know this sounds like a stupid question, but I really don’t see the

  • 0

I know this sounds like a stupid question, but I really don’t see the root cause right now…

I just figured out to upload image using ajax with the help of jQuery-File-Upload and Paperclip, everything is quite fine, the file is uploaded, the database entry is successfully saved.

The only problem is the <%= image_tag @attached_image.image.url %> is not working in my create.js.erb, with which I would like to make an entry on the view with javascript. But the url of the uploaded file instance is correct.

it’s working if I do:

$("#attached-images").append("<li><img src='http://localhost:3000<%= @attached_image.image.url %>'></img></li>")

but it’s not working if I do, which is from Paperclips Github Readme:

$("#attached-images").append("<li><%= image_tag @attached_image.image.url %></li>")

and there’s no exception raised in the console, there’s just nothing comes up. I am really confused..and is there anyway that I could debug the js.erb processing in the browser?

My view:

<div id="upload-and-insert-image-dialog"> 
<%= form_for :attached_image, :remote => true, :url => attached_images_path(), :html => { :class => "upload", :multipart => true } do |f| %>
  <%= f.file_field :image %>
<% end %>
</div>
<ul id="attached-images">
</ul>

My controller:

class AttachedImagesController < ApplicationController
  def create
    @attached_image = AttachedImage.new(params[:attached_image])

    respond_to do |format|
      if @attached_image.save
        format.js
      else
        format.js { render 'attached_images/create_error' }
      end
    end
  end
end

My attached_images/create.js.erb:

$("#attached-images").append("<li><%= image_tag @attached_image.image.url %></li>")

My model:

class AttachedImage < ActiveRecord::Base
  belongs_to :attachable, :polymorphic => true

  has_attached_file :image
end
  • 1 1 Answer
  • 1 View
  • 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-28T18:52:53+00:00Added an answer on May 28, 2026 at 6:52 pm

    I found the problem, it’s because that I missed the escape_javascript function, the following code works very well.

    $("#attached-images").append("<li><%= escape_javascript(image_tag(@attached_image.image.url)) %></li>")
    

    many thanks to @varatis, you remind me of that.

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

Sidebar

Related Questions

I know this sounds like a stupid question, but here it is: Is there
I know this sounds like a really obvious question, but it's proving harder to
This sounds like a trivia question but I really need to know. If you
I know this sounds like a dumb question but I need to ask this.
This probably sounds like a stupid question, but I'm going to give it a
I know this sounds like a simple question, but I just wasted the last
I don't really understand this article . But it sounds like you can compile
I know this sounds like a dumb question, but it's to settle an argument
I know this may sound like a stupid question, but numerous google searches haven't
I know this sounds like an odd question, but I need to keep a

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.