Search code examples
ruby-on-railsruby-on-rails-2

how to catch value of symbol :confirm in rails


<%= f.submit "#{t('next_text')}", :class => "submit_button" ,:confirm=>'Edit all copies?'%>

how can I take value(true or false) of :confirm in rails 2.3.5? I need this value to do some action in controller .


Solution

  • The easiest solution would be to just add a checkbox to your form whether or not to edit all copies.

    If you really need the confirmation box on submit, attach an onSubmit handler to the form

    <% form_for(@some_model, :html=> {:class => 'edit_confirmation'}) do |f| %>
      <%= hidden_field_tag :edit_all, 0 %> 
      ....
    <% end %>
    

    The javascript using jQuery:

    $('form.edit_confirmation').on('submit', function(e) {
    
      // the hidden field
      var field  = $('input#edit_all');
    
      if(confirm("Edit all copies?")) {
        field.val(1); 
      } else {
        field.val(0);
      }
    
      return true;
    });
    

    In your controller you can get the result with params[:edit_all]