简体   繁体   English

水平形式不适用于bootstrap-sass rails gem

[英]form-horizontal not working with bootstrap-sass rails gem

I have the following new.html.erb taken and edited from the Devise gem. 我从Devise gem中获取并编辑了以下new.html.erb。

<h2>Sign in</h2>

<%= simple_form_for(resource, as: resource_name, url: session_path(resource_name), html:{class: "form-horizontal"}) do |f| %>

<%= f.input :email%>
<%= f.input :password%>
<%= f.input :remember_me, as: :boolean%>

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

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

but it returns the following instead http://imgur.com/3l4rLTW 但它返回以下内容,而不是http://imgur.com/3l4rLTW

As displayed in the picture, the form did not take upon the form-horizontal property in bootstrap. 如图中所示,该表单没有采用bootstrap中的form-horizo​​ntal属性。 The form description is above instead of next to, and somehow the checkbox is all the way to the right. 表单说明位于上方,而不是旁边,因此复选框始终位于右侧。

What did I do wrong? 我做错了什么? I am following the One Month rails tutorial and it worked when I followed along with the video 我正在关注“一个月轨道”教程,当我跟随视频一起学习时

I found out that there is a problem with ruby gems... when you run bundle install after putting gem 'simple_form' into your gem file, it will still install version 3.0.2 instead of the newest version from github (3.1rc). 我发现红宝石宝石有问题...在将gem 'simple_form'放入宝石文件后运行捆绑安装时,它仍将安装3.0.2版本,而不是github(3.1rc)的最新版本。

What you can do is install this within your gemfile instead: gem 'simple_form', github: 'plataformatec/simple_form', branch: 'master' 您可以做的就是在您的gemfile中安装此文件: gem 'simple_form', github: 'plataformatec/simple_form', branch: 'master'

Then run bundle install. 然后运行捆绑安装。 It should update your gem to the correct version (3.1rc). 它应该将您的gem更新到正确的版本(3.1rc)。 Then, run rails generate simple_form:install --bootstrap again. 然后,运行rails generate simple_form:install --bootstrap再次rails generate simple_form:install --bootstrap Every time it stops with a conflict, type 'y' and then hit enter to overwrite those old initializer files causing the conflict. 每次因冲突而停止时,键入“ y”,然后按Enter键以覆盖那些导致冲突的旧初始化文件。 Terminate the rails server, and then turn it back on. 终止rails服务器,然后将其重新打开。 You should be good to go and see the working bootstrap simple-forms if your code is correct. 如果您的代码是正确的,那么您应该会很高兴去查看工作中的bootstrap简单格式。

For example: 例如:

'<%= simple_form_for(@story, html: { class: 'form-horizontal' }) do |f| %>`

You're code is lacking a lot of classes in order to properly display. 您的代码缺少很多classes才能正确显示。

Bootstrap Form-Horizontal Doc 引导表格水平文档

<div class="panel panel-default">
    <div class="panel-heading">
        <div class="panel-title">
            <h1>Sign in</h1>
        </div>
    </div>
    <div class="panel-body">
        <%= form_for(resource, :as => resource_name, :url => session_path(resource_name)) do |f| %>

          <div class="form-group">
            <%= f.label :email %>
            <%= f.email_field :email, class: "form-control", :autofocus => true %>
            </div>

          <div class="form-group">
            <%= f.label :password %>
            <%= f.password_field :password, class: "form-control" %>
          </div>

        <div class="form-group">
            <div class="checkbox">
                <%= f.check_box :remember_me %> 
                <%= f.label :remember_me %>
            </div>
        </div>

          <div class="form-group">
            <%= f.submit "Sign in", class: "btn btn-primary" %>
          </div>
        <% end %>
    </div>
    <div class="panel-footer">
        <%= render "devise/shared/links" %>
    </div>
</div>

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

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