Forum: Ruby on Rails Ajax form in a normal form

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
Guillaume L. (Guest)
on 2009-02-20 22:09
Hello everyone!
Here is my problem. I have a form to create a ticket, and I want to
upload a file in the same time.
Basically, a user fill the form and then can attach a file while editing
his  ticket. But what I want to do here, is to send the file during the
creation of the ticket.

This is the form to create a ticket :

<% form_for(@ticket) do |f| %>

  # My first field
  <%= f.label :subject, 'Subject: '%>
  <%= f.text_field :subject, :size => 70 %>

  # Submit button
  <%= f.submit "Create" %>
<% end %>

And I want to add this form (see underneath) into the first form
(mentioned above). But instead of sending POST data for this second
form, I'd like to add this variables as hidden fields in the first form.

<% form_for(@ticket_attachment, :html => { :multipart => true }) do |f|

    <label>File: </label>
    <%= file_field(:ticket_attachment, :file) %>

    <%= hidden_field :ticket_attachment, :first_thing %>
    <%= hidden_field :ticket_attachment, :second_thing %>

    <%= f.submit "Upload" %>

<% end %>

Is that possible?! Maybe with ajax?

Thank you!
Matt J. (Guest)
on 2009-02-21 21:04
(Received via mailing list)
You're going to have problems - AJAX can't typically access file
fields (for
security reasons). Is there any reason that you can't just add the
file fields
directly to the ticket? Maybe with some JS to show/hide them?

--Matt J.

On Feb 20, 3:09 pm, Guillaume L. <rails-mailing-l...@andreas-
This topic is locked and can not be replied to.