简体   繁体   English

Ruby on Rails:simple_form + Twitter引导程序未显示

[英]Ruby on Rails: simple_form + Twitter Bootstrap not showing up

I'm creating a simple sign_up form for new users on my site. 我正在为我的网站上的新用户创建一个简单的sign_up表单。 I have ran the install for simple_form bootstrap... 我已经运行了simple_form引导程序的安装...

rails g simple_form:install --bootstrap

However, it's still not showing up and rendering as a normal simple_form. 但是,它仍然没有显示和呈现为普通的simple_form。

Here is my form code: 这是我的表单代码:

<h2>Sign up</h2>

<%= simple_form_for(resource, :as => resource_name, :url => registration_path(resource_name ), :html => {:class => 'form-horizontal' }) do |f| %>
  <%= f.error_notification %>


    <%= f.input :username, :required => true, class: "form-control"%>
    <%= f.input :first_name, :required => true, class: "form-control" %>
    <%= f.input :last_name, :required => true, class: "form-control" %>
    <%= f.input :twitter, class: "form-control", type: "text", placeholder: "Username" %>
    <%= f.input :bio, class: "form-control" %>
    <%= f.input :email, :required => true, :autofocus => true, class: "form-control" %>

  <div class="form-actions">
    <%= f.button :submit, "Sign up", class: "btn btn-primary btn-sm" %>
  </div>
<% end %>

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

Not sure what I'm doing wrong here. 不知道我在做什么错。 Thanks in advance. 提前致谢。

The sample application here mentions how you need to download Bootstrap separately (they use curl) and place it in vendor/assets/stylesheets/bootstrap.css. 这里的示例应用程序提到了您需要如何分别下载Bootstrap(它们使用curl)并将其放置在vendor / assets / stylesheets / bootstrap.css中。

Please try that. 请尝试一下。

It sounds like Bootstrap is not installed in your application or maybe you are trying to use Bootstrap 3. At the time I typed this on 2013-10-13, Simple Form did not support Bootstrap 3. See here for more details. 听起来您的应用程序中没有安装Bootstrap,或者您尝试使用Bootstrap3。在2013年10月13日键入此代码时,Simple Form不支持​​Bootstrap3。有关更多详细信息,请参见此处

So that means you need to add Bootstrap 2.x to your application and Vidya has provided some good direction already. 因此,这意味着您需要将Bootstrap 2.x添加到您的应用程序中,并且Vidya已经提供了一些很好的指导。

If you are interested in using a gem to add Bootstrap 2.x, then I've provided instructions for twitter-bootstrap-rails below. 如果您对使用gem添加Bootstrap 2.x感兴趣,那么我在下面提供了twitter-bootstrap-rails的说明。 Be sure to review their readme as well in case I omitted something. 如果我省略了一些内容,请务必也阅读他们的自述文件

In your gemfile add: 在您的gemfile中添加:

gem "twitter-bootstrap-rails", :git => 'git://github.com/seyhunak/twitter-bootstrap-rails.git'

Then at the rails console for your project run (I've assumed you want less support): 然后在Rails控制台上运行您的项目(我假设您想减少支持):

bundle install
rails generate bootstrap:install less

Depending on whether you want a fixed or static layout use one of the two lines below: 根据您要的是固定布局还是静态布局,请使用以下两行之一:

rails g bootstrap:layout application fixed
rails g bootstrap:layout application fluid

Finally, edit your application.css file (found in app/assets/stylesheets) so it has 'require bootstrap_and_overrides similar to the example below: 最后,编辑您的application.css文件(位于app / assets / stylesheets中),使其具有类似于以下示例的“ bootstrap_and_overrides”:

*= require_self
*= require bootstrap_and_overrides
*= require_tree .

I'm pretty sure this happens by default now but you might also want to confirm that you have 'require twitter/bootstrap in your application.js as well (found in app/assets/javascripts). 我很确定现在默认情况下会发生这种情况,但是您可能还想确认一下,在application.js中也需要“ twitter / bootstrap”(位于app / assets / javascripts中)。 An example from a project of mine is below: 下面是我的一个项目的示例:

//= require jquery
//= require jquery_ujs
//= require twitter/bootstrap
//= require turbolinks
//= require_tree .

If it still doesn't work and you added this gem. 如果仍然无法正常工作,则您添加了此gem。 Kindly let me know what version of ruby, rails, simple_form and twitter-bootstrap-rails you are using. 请让我知道您使用的是什么版本的ruby,rails,simple_form和twitter-bootstrap-rails。

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

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