我在我的用户控制器中为我的新操作和编辑操作设置了模式。为了保持显示的一致性,我希望我的用户显示页面也以模态显示。
现在用户通过
访问他们的节目页面<li><%= link_to "View Profile", current_user %></li>
导航栏中的链接。
我想设置此链接以在我的用户控制器中显示show动作的所需模式。
我卡住了,我试图谷歌如何做到这一点,但我不认为我在问正确的问题。如果有人可以指导我使用资源或者给我一些如何实现这一目标的大纲,我们将不胜感激!
我意识到这个问题有点模糊,但我不确定如何继续进行。
答案 0 :(得分:1)
可能是这样的:
<!-- Trigger the modal with a button -->
<button type="button" class="btn btn-info btn-lg" data-toggle="modal" data-target="#myModal">Open Modal</button>
<!-- Modal -->
<div id="myModal" class="modal fade" role="dialog">
<div class="modal-dialog">
<!-- Modal content-->
<div class="modal-content">
<%= render 'users/show', user: current_user %>
</div>
</div>
</div>
答案 1 :(得分:1)
如果您只想在单击时加载配置文件,则可以使用rails js。
1。在链接代码上设置remote: true
。
<li><%= link_to "View Profile", current_user, remote: true %></li>
2. 创建包含模态的部分,以便我们可以通过rails js渲染它。
app/views/users/_show.html.erb
<%= content_tag :div, class: "modal fade", id: dom_id(@user, :modal) do %>
<div class="modal-dialog">
<div class="modal-content">
Lorem ipsum...
</div>
</div>
<% end %>
3. 追加包含模态的部分,然后使用rails js切换它。当设置.js.erb
时,Rails将查找相应的remote: true
视图。
app/views/users/show.js.erb
$('body').append('<%= j render "users/show" %>'); // Append modal
$('#<%= dom_id @user, :modal %>').modal('toggle'); // Toggle modal