【问题标题】:Rails 3 best_in_place_if how to show confirm alert box before the action gets completedRails 3 best_in_place_if 如何在操作完成之前显示确认警报框
【发布时间】:2016-09-24 04:04:35
【问题描述】:

我正在使用 best_in_place_if 进行内联编辑。在这里,只需单击该值即可更改列值。假设列是状态,值是“是”和“否”。所以它就像一个切换效果。如果用户单击此列,则会调用服务器并触发查询以切换数据库中的值。

我想显示一个显示确认消息的警报框,就像我们对删除所做的那样。如果用户单击是,那么很好,否则不完成呼叫。

best_in_place_if(current_user.admin,trip,:is_active, :type => :checkbox, :classes => 'trip_disable')

【问题讨论】:

    标签: jquery ruby-on-rails ruby-on-rails-3 best-in-place


    【解决方案1】:

    为了保持它的 rails 风格,我会尝试利用 jquery-ujs 和我们 rails 开发人员非常喜欢的 data-confirm 属性。尝试将 best_in_place 调用包装在链接内的跨度内,并在其上调用 data-confirm 选项。如:

       <%= link_to(trip) do %>
         <span><%= best_in_place trip, :is_active, type: :checkbox, classes: 'trip_disable', data: {confirm: "Are you sure?"} %> </span> 
       <% end %>
    

    您可能需要更改我通过手机执行此操作的跨度,因此格式可能会有所偏差。

    【讨论】:

      猜你喜欢
      • 2018-03-27
      • 1970-01-01
      • 1970-01-01
      • 2014-03-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多