首页 > 解决方案 > 在 Rails 中的模式上检查远程真

问题描述

我正在使用 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-railstwitter-bootstrap

解决方案


从视图/部分角度来看 - 它是否在模态中呈现没有区别remote:true,因此您必须以某种方式传递该知识。例如 - 使用局部变量:

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

推荐阅读