views:

102

answers:

3

I am trying to have a way of confirming the information entered before actually saving it to the DB

Considered making an individual confirmation page as discussed here

http://stackoverflow.com/questions/445293/ruby-on-rails-confirmation-page-for-activerecord-object-creation

However my form includes an attached file using paperclip which makes it more of a hassle to implement.

I thought of just having a :confirm => pop up that would show the information that the user had just entered.

The problem is how to show the information that the user had just entered, for example

<% form_for @entry, :html => { :multipart => true } do |f| %>
  <%= f.error_messages %>


    <%= f.label :name %><br />
    <%= f.text_field :name %>

    <%= f.label :file %><br />
    <%= f.file_field :file %>

    <%= f.submit 'Create', :confirm => "????? " %>

<% end %>
+1  A: 

The confirm option for the Rails submit method can only take a text value.

If you want to dynamically generate the confirm text, one way you could do it is to write your own HTML submit tag, and write custom javascript to analyse the fields you want to use in your generated text.

Or you could use the Rails submit method, but use something like JQuery to add an event handler to it.

DanSingerman
+1  A: 

I'd just throw my js into an onclick handler. That's all Rails does.

<%= f.submit 'Create', :onclick => "confirm('Name is ' + $F('entry_name'));" %>

(note, didn't test that, but it looks close. confirm is a core js function, not part of any lib)

MattMcKnight
+1  A: 

Given that your loading attachments it may not be a bad idea to render a staging view including information derived from the attachment allowing the user to confirm. As in display the file if it's an image, or the first paragraph of text if it's a text file, etc.

It's going to take more work than the just adding a confirm pop up, but I feel the enhanced user experience is worth the extra effort.

I'm not familiar with the way that paperclip works. So you're mostly on your own for the intimate details.

You will probably have to create a record before the staging view can be rendered with the sample of the uploaded file. To accomplish that I'd set up an "active" column on the model in question, that defaults to false.

Usage would look something like this:

  1. User complets new form.
  2. Attachment is updated and records are saved, with the active field set to false.
  3. Redirected to confirmation page that is essentially the show page with a confirm link/button and a cancel link/button
  4. a. When the confirm link/button is clicked it sends a request to the controller triggering the update action on this record setting active to true.

    b. When the cancel link/button is clicked it sends a request to the controller trigering the destroy action on this record.

All that's left is to set up a recurring task to remove objects that are inactive and were crated long enough ago that it's safe to assume the user has just ended the browser session.

EmFi