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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T23:32:22+00:00 2026-06-09T23:32:22+00:00

I’m using the jQuery File Upload plugin (documentation here ) integrated into my Rails

  • 0

I’m using the jQuery File Upload plugin (documentation here) integrated into my Rails 3.2.1 app (set up based on documentation here) to upload photos into my app.

I’ve set up the plugin so that it automatically uploads all the files that have been selected without the user having to do anything else. Once the photos have been uploaded (and the according entries created in the DB), I’d like the user to be able to enter a title for each of the photos.

However, in the template script that displays the uploaded photos, I’m struggling to create an edit form for each of the photos that have been uploaded. I know creating a form for each photo is far from elegant, but it appears to be the only way in this context (unless I’m missing something obvious here?).

<script id="template-download" type="text/html">
    {% for (var i=0, files=o.files, l=files.length, file=files[0]; i<l; file=files[++i]) { %}
            <div class="template-download nofade">
                {% if (file.error) { %}
                    {%=file.name%}
                    <span>{%=fileUploadErrors[file.error] || file.error%}</span>
                {% } else { %}
                    {% if (file.thumbnail_url) { %}
                        <a href="{%=file.url%}" title="{%=file.name%}" rel="gallery"><img src="{%=file.mini_url%}"></a>
                        <%= form_for Photo.find(<---- ID SHOULD BE HERE ---->) do |f| %>
                            <%= f.text_field :title %>
                            <button class="btn btn-danger btn-small" data-type="{%=file.delete_type%}" data-url="{%=file.delete_url%}"><i class="icon-white icon-trash"></i> Delete</button>
                            <%= f.submit %>
                        <% end %>
                    {% } %}
                {% } %}
            </div>
    {% } %}
</script>

I have a variable which is

file.photo_id

that contains the ID of the relevant photo, but trying to create a form for it from

<%= form_for Photo.find("{%= file.photo_id %}") do |f| %>

only returns this error:

Couldn't find Photo with id={%= file.photo_id %}

I’ve tried variations like Photo.find({%= file.photo_id %}) too, but to no avail.

I know this is quite a specific problem to a specific plugin, but thought it might still be worth asking. Anyone know how to pass in the photo ID, or even better has hints of how to solve this problem in a more elegant manner?

  • 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-06-09T23:32:24+00:00Added an answer on June 9, 2026 at 11:32 pm

    After all files uploaded, the plugin will list down all files using template-download

    I would recommend to use ajax over form submit to update title of each file shown on the page.

    Here is how you can achieve this

    <script id="template-download" type="text/html">
        {% for (var i=0, files=o.files, l=files.length, file=files[0]; i<l; file=files[++i]) { %}
                <div class="template-download nofade">
                    {% if (file.error) { %}
                        {%=file.name%}
                        <span>{%=fileUploadErrors[file.error] || file.error%}</span>
                    {% } else { %}
                        {% if (file.thumbnail_url) { %}
                            <a href="{%=file.url%}" title="{%=file.name%}" rel="gallery"><img src="{%=file.mini_url%}"></a>
                                <input type="text" size="30" name="photo"/>
                                <a href="photos/{%=file.photo_id%}" class=".update-btn">Save</a>
                                <button class="btn btn-danger btn-small" data-type="{%=file.delete_type%}" data-url="{%=file.delete_url%}"><i class="icon-white icon-trash"></i> Delete</button>
                        {% } %}
                    {% } %}
                </div>
        {% } %}
    </script>
    

    If you notice, I have replace form_tag with

    <input type="text" size="30" name="photo"/>
    <a href="photos/{%=file.photo_id%}" class=".update-btn">Save</a>
    

    Now you will see Save link beside each textbox to enter title.

    Next is action on clicking the link.

    $(function() {
         $('.update-btn').live("click", function() {
            var title = $(this).previous();
            $.ajax({
                url: $(this).attr('href'),
                type: "POST",
                data: { _method: 'PUT', title.attr('name'): title.val() },
                dataType: 'json',            
                success: function(msg) {
                   //You may disable link after successful action
                }
            });
         });
      });
    

    Above code binds click event to each Save link and send PUT request to PhotosController.

    I am not good at javascript/jQuery but it should work.

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

Sidebar

Related Questions

We're building an app, our first using Rails 3, and we're having to build
I am using Paperclip to handle profile photo uploads in my app. They upload
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am reading a book about Javascript and jQuery and using one of the
We are using XSLT to translate a RIXML file to XML. Our RIXML contains
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I have a jquery bug and I've been looking for hours now, I can't

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.