0

我目前正在尝试为 Rails 应用程序中的登录设置一个非常基本的灯箱效果。我正在使用插件 Lightbox Evolution。用法如下:

  • 确保它是有效的 DOCTYPE。
  • 在要使用灯箱的页面头部包含 jQuery 库灯箱 CSS 和灯箱 js 文件
  • 初始化插件:

    <script type="text/javascript" jQuery(document).ready(function($){ $('.lightbox').lightbox(); }); </script>

jquery.lightbox.min.js 和 jquery.lightbox.css 分别位于 vendor/assets/javascripts 和 vendor/assets/stylesheets 目录中。

我已经在 application.html.erb 文件中包含了灯箱脚本,因为我计划在网站的其他地方使用灯箱效果。

我的 application.html.erb 文件如下所示:

<!DOCTYPE html>
<html>
<head>
   <title>Test App</title>
   <%= stylesheet_link_tag    "application", :media => "all" %>
   <%= stylesheet_link_tag    "jquery.lightbox.css", :media => "all" %>   
   <%= javascript_include_tag "application" %>
   <%= javascript_include_tag "jquery.lightbox.min" %>   
   <%= csrf_meta_tags %>
</head>
<body>
   <p class="notice"><%= notice %></p>
   <p class="alert"><%= alert %></p>
   <%= yield %>

   <script type="text/javascript">
 jQuery(document).ready(function($){
    $('.lightbox').lightbox();
  });
   </script>

</body>
</html>

我的登陆页面是 app/views/welcome/index.html.erb:

<h1>Landing Page</h1>
<a href="users/sign_in" class="lightbox">Login</a>

我按照说明使用“灯箱”类。

当我去localhost:3000时,在开发环境中构建的html如下:

<!DOCTYPE html>
<html>
<head>
   <title>MetaLinx Material Management</title>
   <link href="/assets/application.css?body=1" media="all" rel="stylesheet" type="text/css" />
<link href="/assets/bootstrap_and_overrides.css?body=1" media="all" rel="stylesheet" type="text/css" />
<link href="/assets/containers.css?body=1" media="all" rel="stylesheet" type="text/css" />
<link href="/assets/scaffolds.css?body=1" media="all" rel="stylesheet" type="text/css" />
<link href="/assets/scales.css?body=1" media="all" rel="stylesheet" type="text/css" />
<link href="/assets/welcome.css?body=1" media="all" rel="stylesheet" type="text/css" />
   <link href="/assets/jquery.lightbox.css?body=1" media="all" rel="stylesheet" type="text/css" />   
   <script src="/assets/jquery.js?body=1" type="text/javascript"></script>
<script src="/assets/jquery_ujs.js?body=1" type="text/javascript"></script>
<script src="/assets/twitter/bootstrap/bootstrap-transition.js?body=1" type="text/javascript"></script>
<script src="/assets/twitter/bootstrap/bootstrap-alert.js?body=1" type="text/javascript"></script>
<script src="/assets/twitter/bootstrap/bootstrap-modal.js?body=1" type="text/javascript"></script>
<script src="/assets/twitter/bootstrap/bootstrap-dropdown.js?body=1" type="text/javascript"></script>
<script src="/assets/twitter/bootstrap/bootstrap-scrollspy.js?body=1" type="text/javascript"></script>
<script src="/assets/twitter/bootstrap/bootstrap-tab.js?body=1" type="text/javascript"></script>
<script src="/assets/twitter/bootstrap/bootstrap-tooltip.js?body=1" type="text/javascript"></script>
<script src="/assets/twitter/bootstrap/bootstrap-popover.js?body=1" type="text/javascript"></script>
<script src="/assets/twitter/bootstrap/bootstrap-button.js?body=1" type="text/javascript"></script>
<script src="/assets/twitter/bootstrap/bootstrap-collapse.js?body=1" type="text/javascript"></script>
<script src="/assets/twitter/bootstrap/bootstrap-carousel.js?body=1" type="text/javascript"></script>
<script src="/assets/twitter/bootstrap/bootstrap-typeahead.js?body=1" type="text/javascript"></script>
<script src="/assets/twitter/bootstrap/bootstrap-affix.js?body=1" type="text/javascript"></script>
<script src="/assets/twitter/bootstrap.js?body=1" type="text/javascript"></script>
<script src="/assets/bootstrap.js?body=1" type="text/javascript"></script>
<script src="/assets/containers.js?body=1" type="text/javascript"></script>
<script src="/assets/jquery.ui.effect.js?body=1" type="text/javascript"></script>
<script src="/assets/jquery.ui.core.js?body=1" type="text/javascript"></script>
<script src="/assets/jquery.ui.widget.js?body=1" type="text/javascript"></script>
<script src="/assets/jquery.ui.mouse.js?body=1" type="text/javascript"></script>
<script src="/assets/jquery.ui.sortable.js?body=1" type="text/javascript"></script>
<script src="/assets/jquery.ui.position.js?body=1" type="text/javascript"></script>
<script src="/assets/jquery.ui.menu.js?body=1" type="text/javascript"></script>
<script src="/assets/jquery.ui.autocomplete.js?body=1" type="text/javascript"></script>
<script src="/assets/jquery.ui.datepicker.js?body=1" type="text/javascript"></script>
<script src="/assets/rails_admin/jquery.ui.timepicker.js?body=1" type="text/javascript"></script>
<script src="/assets/rails_admin/ra.datetimepicker.js?body=1" type="text/javascript"></script>
<script src="/assets/rails_admin/jquery.colorpicker.js?body=1" type="text/javascript"></script>
<script src="/assets/rails_admin/ra.filter-box.js?body=1" type="text/javascript"></script>
<script src="/assets/rails_admin/ra.filtering-multiselect.js?body=1" type="text/javascript"></script>
<script src="/assets/rails_admin/ra.filtering-select.js?body=1" type="text/javascript"></script>
<script src="/assets/rails_admin/ra.remote-form.js?body=1" type="text/javascript"></script>
<script src="/assets/rails_admin/jquery.pjax.js?body=1" type="text/javascript"></script>
<script src="/assets/jquery_nested_form.js?body=1" type="text/javascript"></script>
<script src="/assets/rails_admin/ra.nested-form-hooks.js?body=1" type="text/javascript"></script>
<script src="/assets/rails_admin/ra.widgets.js?body=1" type="text/javascript"></script>
<script src="/assets/rails_admin/ui.js?body=1" type="text/javascript"></script>
<script src="/assets/rails_admin/custom/ui.js?body=1" type="text/javascript"></script>
<script src="/assets/rails_admin/rails_admin.js?body=1" type="text/javascript"></script>
<script src="/assets/scales.js?body=1" type="text/javascript"></script>
<script src="/assets/welcome.js?body=1" type="text/javascript"></script>
<script src="/assets/application.js?body=1" type="text/javascript"></script>
    <script src="/assets/jquery.lightbox.min.js?body=1" type="text/javascript"></script>   
    <meta content="authenticity_token" name="csrf-param" />
 <meta content="NGWSCp8qKAwi52ViQNfSP+2WG4teWxwOzCDCFfqQaLc=" name="csrf-token" />
 </head>
 <body>
   <p class="notice"></p>
   <p class="alert"></p>
   <h1>Landing Page</h1>
 <p>Find me in app/views/welcome/index.html.erb</p>

<a href="users/sign_in" class="lightbox">Login</a>


    <script type="text/javascript">
      jQuery(document).ready(function($){
      $('.lightbox').lightbox();
    });
    </script>
</body>

我正在使用设计进行身份验证,因此它为用户/登录设置了路由。当我单击上面的链接时,它会将我带到用户/新页面,但它不会在灯箱中弹出。生成的 html 如下所示:

应用程序/视图/会话/new.html.erb:

<h2>Sign in</h2>

    <%= form_for(resource, :as => resource_name, :url => session_path(resource_name)) do |f| %>
  <div><%= f.label :email %><br />
  <%= f.email_field :email, :autofocus => true %></div>

  <div><%= f.label :password %><br />
  <%= f.password_field :password %></div>

  <% if devise_mapping.rememberable? -%>
    <div><%= f.check_box :remember_me %> <%= f.label :remember_me %></div>
  <% end -%>

  <div><%= f.submit "Sign in" %></div>
<% end %>

<%= render "devise/shared/links" %>

所以问题是我做错了什么,所以当我单击 app/views/welcome/new.html.erb 中的“登录”链接时,它会将我带到登录页面,而不是使用灯箱 jQuery 弹出它?

4

1 回答 1

0

尝试更改href="users/sign_in"href="#". 因为如果您只想单击它并让灯箱弹出登录表单,链接真的无关紧要。

于 2013-01-26T05:27:56.050 回答