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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T03:00:57+00:00 2026-05-27T03:00:57+00:00

There are interesting task: my active record ‘ Event ‘ entity can contain one

  • 0

There are interesting task: my active record ‘Event‘ entity can contain one ‘Attachment‘ PDF file. On the Create Event page, user can Upload this attachment BEFORE Submits that Event. Attachment uploads to Amazon via Ajax, progress-bar displays etc blablabla.
It should be displayed in_a_way:

= form_for @event do |e|
  = e.text_field :name

  = form_for @attach, :remote=>true, html=>{:multipart=>true} do |at|
    = at.file_field :pdf, :accept=>"pdf", :size=>"1"
    = at.submit

  = e.submit

Yes, this is just pseudo-code, and I don’t mind how it can work, but the main idea is presents: [Submit Attachment] button should be placed inside the Event form.
How I can implement it? Maybe, just make some offset to nested Attachment form so it will be displayed inside Event form, or there are any others solutions?

………………………………………………php_vs_rails…………………………………………….

  • 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-27T03:00:58+00:00Added an answer on May 27, 2026 at 3:00 am

    Solution: override form headers
    This is a form for creating new event.
    Inside this form, we need ajax file uploading.
    There is a solution: mixing single form between two different types of submits: ajax(js) and html:

    = form_for @event, html=>{:multipart=>true} do |e|
      = e.text_field :name
    
      = file_field_tag "attach[pdf]", :id=>"attach_pdf", :accept => "pdf", :maxlength => "200"
      = submit_tag "", :id => "ajax_submit", :style=>"display:none"
    
      = e.submit    <!-- id = "new_event_submit" -->
    
    ////////////////////////////
    // before 'submits' call override functions:
    
    $("#ajax_submit").click(function(){
        prepeareFormForAjax();
        return true;
    });
    
    $("#new_event_submit").click(function(){
      prepeareFormForHtml();
      return true;
    });
    
    //////////////////////////////
    // to store original (previous, html) form data
    var html_form_action = "";
    var html_form_method = "";
    ///////////////////////////////
    
    /* 
     * To ajax file upload:
     **/
    function prepeareFormForAjax() {
      $("form").attr("data-remote", "true");
      $("form").attr("enctype", "multipart/form-data");  
    
      html_form_action = $("form").attr("action");  // save old action
      $("form").attr("action", "/attach");            // I need /nors action
    
      //_method field is a hidden form field, maybe you have it too on the page:
      if ($('input[name="_method"]').length != 0) {
        html_form_method = $('input[name="_method"]').val();
        $('input[name="_method"]').val("post");
      }
    
    }
    
    function prepeareFormForHtml() {
      $("form").removeAttr("data-remote");
      $("form").removeAttr("enctype");
      if (html_form_action != "") {
        $("form").attr("action", html_form_action);
        html_form_action = "";
      }
      if (html_form_method != "") {
        $('input[name="_method"]').val(html_form_method);
        html_form_method = "";
      }
    }
    
    ///////////////////////
    

    Now, to upload file via AJAX use:

    $("#ajax_submit").click();
    

    any questions?

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

Sidebar

Related Questions

there's this interesting problem i can not solve myself. I will be very glad,
What is the string concatenation operator in Oracle SQL? Are there any interesting features
There is an interesting post over here about this, in relation to cross-application flow
There was an interesting question in a practice test that I did not understand
There was an interesting problem in C++, but it was more about architecture. There
I have heard that there is lots of interesting and useful WSGI middleware around.
Is there a better way than using globals to get interesting values from a
AOP is an interesting programming paradigm in my opinion. However, there haven't been discussions
Intel's Threading Building Blocks (TBB) open source library looks really interesting. Even though there's
Some days ago I looked at boost sources and found interesting typedef . There

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.