Modal - gagoar/SrBuj GitHub Wiki

view:

 = link_to 'add Element', elements_path, remote: true, data: {target: 'partial-id', modal: true}
 #list

#partial-id

controller:

 def new
   @element= Element.new
   respond_to do |format|
    format.js do
      render partial: 'new', content_type: 'text/html' #=> the content_type is needed for request gets success     respond 
 end

_new.haml (partial):

 .modal
   = form_for @element, remote: true, html: { data: {target: 'list', error: 'partial-id', modal: true}, class:  'form-horizontal-ev form-modal'}) do |f|
     .modal-header
       %h3 Add a New Element
     .modal-body
       .control-group
         = f.text_field :name
       .control-group
         = f.text_area :description
     .modal-footer
       = link_to_function 'Close', "$('#modal').modal('toggle');", class: 'btn'
       = f.submit 'Save', data: { disable_with: 'Saving' }, class: 'btn btn-primary'