Forum: Ruby on Rails Ajax form in a normal form

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
007bac1f27905cd4d5d88315e9b0093a?d=identicon&s=25 Guillaume Loader (loader)
on 2009-02-20 21: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!
6883e5ef03484d4fcef507d7b4f1d243?d=identicon&s=25 Matt Jones (Guest)
on 2009-02-21 20: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 Jones


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