ruby-on-rails - 在 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
这附近有工作吗?
解决方案
从视图/部分角度来看 - 它是否在模态中呈现没有区别remote:true
,因此您必须以某种方式传递该知识。例如 - 使用局部变量:
<% in_modal ||= false %>
...
<% if in_modal %>
<button...
<% else %>
<%= link_to ... %>
<% end %>
<%= render partial: 'your_partial', locals:{ in_modal: true } %>
推荐阅读
- sql - SQL有没有办法选择相同列不相似的行
- javascript - 如何在javascript中转换字符串dd-MMM-yyyy HH:mm int0日期时间格式
- kong - 您如何将来自多个请求的响应组合为客户端的单个响应?
- php - php-mysql重复行
- mysql - 合并具有缺失值的集合 laravel
- java - 为什么 String.split(":") 不能正常工作?
- angular - 垫子对话框中垫子选择的打开选项列表未关闭
- sql - sql查询速度慢如何优化
- react-native - 如何在本机反应中检查设备是否连接到蓝牙?
- python - 如何通过表格和图表图像制作下面描述的 CNN 网络?