【问题标题】:Checking remote true on modal in Rails在 Rails 中的模式上检查远程真
【发布时间】:2020-01-22 13:21:30
【问题描述】:

我正在使用 Rails 5 和引导模式。我试图弄清楚是否有办法在用户以模式查看数据时显示关闭按钮,并且当它只是一个常规的显示导轨页面时有一个常规链接。

if modal || remote: true
show this:
     <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
else 
     <%= link_to "Cancel", contacts_path, class: "btn btn-outline-secondary border-button mt-n3", id: "cancel-btn", ":data-dismiss" => "modal" %>
end

这里有解决办法吗?

【问题讨论】:

    标签: ruby-on-rails twitter-bootstrap


    【解决方案1】:

    从视图/局部的角度来看 - 无论是否在模态框内渲染,remote:true 都没有区别,因此您必须以某种方式传递这些知识。例如 - 使用局部变量:

    <% in_modal ||= false %>
    ...
    <% if in_modal %>
      <button...
    <% else %>
      <%= link_to ... %>
    <% end %>
    
    <%= render partial: 'your_partial', locals:{ in_modal: true } %>
    

    【讨论】:

    • $('#modal-show-body').html('&lt;%= j render("show_single", locals:{ in_modal: true }) %&gt;'); 试过这个但没有用
    • show_single 是我通过 ajax 渲染的部分
    猜你喜欢
    • 1970-01-01
    • 2011-01-13
    • 2018-12-06
    • 1970-01-01
    • 1970-01-01
    • 2012-02-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多