Ruby on Rails:simple_form + Twitter Bootstrap 没有出现 [英] Ruby on Rails: simple_form + Twitter Bootstrap not showing up

查看:23
本文介绍了Ruby on Rails:simple_form + Twitter Bootstrap 没有出现的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为我网站上的新用户创建一个简单的注册表单.我已经为 simple_form 引导程序运行了安装...

rails g simple_form:install --bootstrap

但是,它仍然没有作为普通的 simple_form 显示和渲染.

这是我的表单代码:

注册

<%= simple_form_for(resource, :as => resource_name, :url => registration_path(resource_name ), :html => {:class => 'form-horizo​​ntal' }) do |f|%><%= f.error_notification %><%= f.input :username, :required =>真,类:表单控件"%><%= f.input :first_name, :required =>真,类:表单控件"%><%= f.input :last_name, :required =>真,类:表单控件"%><%= f.input :twitter, class: "form-control", type: "text", placeholder: "Username" %><%= f.input :bio, class: "form-control" %><%= f.input :email, :required =>真,:自动对焦=>真,类:表单控件"%><div class="form-actions"><%= f.button :submit, "Sign up", class: "btn btn-primary btn-sm" %>

<%结束%><%= 渲染设计/共享/链接"%>

不确定我在这里做错了什么.提前致谢.

解决方案

听起来您的应用程序中没有安装 Bootstrap,或者您可能正在尝试使用 Bootstrap 3.当时我在 2013-10-13 输入了这个,Simple Form 不支持 Bootstrap 3.有关详细信息,请参阅此处.

这意味着您需要将 Bootstrap 2.x 添加到您的应用程序中,并且 Vidya 已经提供了一些好的方向.

如果您有兴趣使用 gem 添加 Bootstrap 2.x,那么我在下面提供了 twitter-bootstrap-rails 的说明.请务必查看他们的自述文件,以防我遗漏了某些内容.

在您的 gemfile 中添加:

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

然后在 Rails 控制台上运行您的项目(我假设您需要较少的支持):

捆绑安装rails 生成引导程序:少安装

根据您想要固定布局还是静态布局,请使用以下两行之一:

rails g bootstrap:layout 应用程序已修复rails g bootstrap:布局应用程序流体

最后,编辑您的 application.css 文件(在 app/assets/stylesheets 中找到),使其具有类似于以下示例的需要 bootstrap_and_overrides":

*= require_self*= 需要 bootstrap_and_overrides*= require_tree .

我很确定现在默认情况下会发生这种情况,但您可能还想确认您的 application.js 中也有需要 twitter/bootstrap"(在 app/assets/javascripts 中找到).我的一个项目的例子如下:

//= 需要 jquery//= 需要 jquery_ujs//= 需要推特/引导程序//= 需要涡轮链接//= require_tree .

如果它仍然不起作用并且您添加了此宝石.请告诉我您使用的是哪个版本的 ruby​​、rails、simple_form 和 twitter-bootstrap-rails.

I'm creating a simple sign_up form for new users on my site. I have ran the install for simple_form bootstrap...

rails g simple_form:install --bootstrap

However, it's still not showing up and rendering as a normal 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.

解决方案

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.

So that means you need to add Bootstrap 2.x to your application and Vidya has provided some good direction already.

If you are interested in using a gem to add Bootstrap 2.x, then I've provided instructions for twitter-bootstrap-rails below. Be sure to review their readme as well in case I omitted something.

In your gemfile add:

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):

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:

*= 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). 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. Kindly let me know what version of ruby, rails, simple_form and twitter-bootstrap-rails you are using.

这篇关于Ruby on Rails:simple_form + Twitter Bootstrap 没有出现的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆