-1
目前正在使用Rails 4項目,我們有用戶登錄和登錄模式。Rails 4 - 嘶嘶聲返回未捕獲錯誤:語法錯誤,無法識別的表達式:[path_name]
當我點擊鏈接打開模式,我得到這樣的錯誤:
爲例: 這是用來啓動模式
if($('.modal').length > 0) {
$("#login").modal();
}
else {
$("body").prepend("<%= escape_javascript(render "remote_sign_in", :formats => [:html]) %>");
$("#login").modal();
}
的js代碼
這是模式本身:
<!-- Modal Login -->
<div class="modal modal-login fade" id="login" tabindex="-1" role="dialog" aria-labelledby="modalLogin" aria-hidden="true">
<div class="modal-dialog modal-sm">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h4 class="modal-title" id="modalLogin">Sign In</h4>
</div>
<div class="modal-body">
<%= simple_form_for(resource, :as => resource_name, :url => registration_path(resource_name), :remote => true, :format => :js, :html => {:class => "form-signin"}) do |f| %>
<div class="form-group">
<label for="" class="sr-only">Email</label>
<%= f.input :email, :autofocus => true, :label => false, :input_html => {:class => 'form-control'}, :placeholder => "Email" %>
</div>
<div class="form-group">
<label for="" class="sr-only">Password</label>
<%= f.input :password, :label => false, :input_html => {:class => 'form-control'}, :placeholder => "Password" %>
</div>
<div>
<%= f.button :submit, "Sign In", :class => "btn-credential btn btn-flat-alizarin btn-block" %>
</div>
<% end %>
</div>
<div class="modal-footer">
<div>
<%= link_to "Forgot your password?", remote_recover_password_path, :remote => true, "data-dismiss" => "modal" %>
</div>
<%= link_to "Create an account", remote_sign_up_path, :remote => true, "data-dismiss" => "modal" %>
<div>
</div>
</div>
</div><!-- /.modal-content -->
</div><!-- /.modal-dialog -->
</div><!-- /.modal
這是導航欄的代碼,這顯示是被點擊的鏈接:
<li>
<%= link_to "Log in", remote_sign_in_path, :remote => true, class: "login", "data-toggle" => "modal" %>
</li>
最後,這是對應的路線:
match 'remote_sign_in', to: 'remote_content#remote_sign_in', via: [:get]
我不知道是怎麼回事錯..我甚至去檢查escape_javascript函數,看看它在輸出什麼,它的工作原理應該如此。由於某種原因Sizzle.js試圖選擇一個名爲「remote_sign_in」的元素?
任何幫助表示讚賞!
感謝 - 但我仍然得到同樣的錯誤與 –
我想這是具體的喜人景象錯誤,因爲這段代碼工作在我的應用程序沒有灒。嘗試將'remote_sign_in'存儲在控制器的一個變量中並在視圖中使用該變量。 – Jason