简体   繁体   English

使用Twitter Bootstrap Navbar(带有设计)登录Rails?

[英]Rails Login with Twitter Bootstrap Navbar (w/ Devise)?

I am trying to use Twitter's Bootstrap (http://twitter.github.com/bootstrap/index.html) with Ruby on Rails (v 3.2.8 with Ruby 1.9.3). 我正在尝试将Twitter的Bootstrap(http://twitter.github.com/bootstrap/index.html)与Ruby on Rails(v 3.2.8与Ruby 1.9.3)一起使用。 I am using Devise for authentication. 我正在使用Devise进行身份验证。

Twitter has a nice sign-in form in their navbar. Twitter的导航栏中有一个不错的登录表单。 (see http://twitter.github.com/bootstrap/examples/hero.html ?) (请参阅http://twitter.github.com/bootstrap/examples/hero.html吗?)

How would I set up my Rails application to use that login? 我将如何设置Rails应用程序以使用该登录名? I can set Rails up to login from its own login page, but how do I use the Navbar login? 我可以将Rails设置为从其自己的登录页面登录,但是如何使用Navbar登录? What would be the controller/model structure? 控制器/模型的结构是什么?

I found this on github, but it does not implement the navbar signup (https://github.com/RailsApps/rails3-bootstrap-devise-cancan/). 我在github上找到了它,但是它没有实现导航栏注册(https://github.com/RailsApps/rails3-bootstrap-devise-cancan/)。

Thanks 谢谢

UPDATE: 更新:

Found the answer : https://github.com/plataformatec/devise/wiki/How-To:-Display-a-custom-sign_in-form-anywhere-in-your-app 找到了答案: https : //github.com/plataformatec/devise/wiki/操作方法-Display-a-custom-sign_in-form-anywhere-in-your-app

You can simply run rails g devise:views and customize the form to display correctly inside the nabvar. 您可以简单地运行rails g devise:views devise rails g devise:views并自定义表单以在nabvar内部正确显示。 The you render it with a render 'devise/sessions/new' inside any of your layouts. 您可以在任何布局中使用render 'devise/sessions/new'渲染它。 For more detail look here . 有关更多详细信息,请参见此处

The code from the example has the following after the tag. 该示例中的代码在标记之后具有以下内容。

        <form class="navbar-form pull-right">
          <input class="span2" placeholder="Email" type="text">
          <input class="span2" placeholder="Password" type="password">
          <button type="submit" class="btn">Sign in</button>
        </form>

I would use this code, but change the form's action and input names to that of my login form. 我将使用此代码,但是将表单的操作和输入名称更改为登录表单的名称。

Just view the source code of your login form and change the necessary values. 只需查看登录表单的源代码并更改必要的值即可。 You could also add in some code similar to below so that it will not show the login form if they are already authenticated. 您还可以添加一些类似于以下的代码,以便如果已经通过身份验证,则不会显示登录表单。

<% if not current_user %>
//login form
<% else %>
//welcome the user and provide logout option
<% end %>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM