我正在创建一个reddit克隆,点击标题上的登录或注册文本会打开一个模式,供用户输入其凭据。
我在这里创建了一个模态部分:
<div class="modal fade" id="popUpWindow">
<div class="modal-dialog">
<div class="modal-content">
<div class="col-md-6">
<!-- header -->
<div class="modal-header">
<button type ="button" class="close" data-dismiss="modal">×</button>
<h3 class="modal-title">CREATE A NEW ACCOUNT</h3>
</div>
<!-- body (form) -->
<div class="modal-body">
<form role="form">
<div class="form-group">
<input type ="username" class="form-control" placeholder="choose a username">
</div>
<div class="form-group">
<input type ="password" class="form-control" placeholder="password">
</div>
<div class="form-group">
<input type ="password_confirmation" class="form-control" placeholder="verify password">
</div>
<div class="form-group">
<input type ="email" class="form-control" placeholder="email">
</div>
</form>
</div>
<!-- button -->
<div class="modal-footer">
<button class="btn btn-primary btn-block">SIGN UP</button>
</div>
</div>
<div class="col-md-6">
<!-- header -->
<div class="modal-header">
<button type ="button" class="close" data-dismiss="modal">×</button>
<h3 class="modal-title">LOG IN</h3>
</div>
<!-- body (form) -->
<div class="modal-body">
<form role="form">
<div class="form-group">
<input type ="username" class="form-control" placeholder="username">
</div>
<div class="form-group">
<input type ="password" class="form-control" placeholder="password">
</div>
</form>
</div>
<!-- button -->
<div class="modal-footer">
<button class="btn btn-primary btn-block">LOG IN</button>
</div>
</div>
</div>
</div>
</div>
现在我尝试从标题部分访问此模式代码:
<header class="navbar navbar-fixed-top navbar-inverse">
<div class="container">
<%= link_to "reddit", root_path , :id => 'logo' %>
<nav>
<ul class="nav navbar-nav navbar-right">
<li>
<%= link_to 'Sign up or log in', "#", data: {toggle: "popUp", target: "#popUpWindow"} %>
</li>
</ul>s
</nav>
</div>
</header>
我认为这一行会通过其id popUpWindow成功打开模态:<%= link_to 'Sign up or log in', "#", data: {toggle: "popUp", target: "#popUpWindow"} %>
没有出现错误,但点击link_to内容不会触发任何打开的内容。
在application.js中我有:
//= require jquery
//= require bootstrap
答案 0 :(得分:0)
http://api.rubyonrails.org/classes/ActionView/Helpers/UrlHelper.html
应该是&lt;%= link_to&#39;注册或登录&#39;,&#34;#&#34;,:data =&gt; {:toggle =&gt; &#34; modal&#34;,:target =&gt; &#34; #popUpWindow&#34;}%&gt;代替?
回答