Twitter Bootstrap Modal提交按钮在Rails中提交和打开模态

时间:2013-06-23 22:14:42

标签: ruby-on-rails twitter-bootstrap modal-dialog

我有以下Twitter Bootstrap模式按钮(haml) - 我想使用此按钮保存我的表单,然后打开模态对话框询问我是否要打印它。如何使此按钮执行提交或保存:

%a.btn{"data-toggle" => "modal", :href => "#myModal", 
  class: 'btn btn-inverse btn-large',
  :role => "button"} Press to Complete Visit

  #myModal.modal.hide.fade{"aria-hidden" => "true",
 "aria-labelledby" => "myModalLabel", :role => "dialog", :tabindex => "-1"}

1 个答案:

答案 0 :(得分:0)

你应该做一个AJAX帖子并有一个端点来接收数据。

HTML:

%a.btn{class: 'btn btn-inverse btn-large',
  id: 'submit-btn',
  :role => "button"} Press to Complete Visit

  #myModal.modal.hide.fade{"aria-hidden" => "true",
  "aria-labelledby" => "myModalLabel", :role => "dialog", :tabindex => "-1"}

使用Javascript:

$('#submit-btn').click(function() { 
  $.ajax({
    type: post,
    url: '/your-end-point',
    data: your_data,
    success: function() {
      $('#myModal').show();
    }
  })
})

滑轨:

的routes.rb

post 'your_end_point' => 'your_controller#submit'

your_controller.rb

def submit
  # Save form data...
  render :json => 'success'
end