ruby-on-rails - 无法在 Ruby on Rails 中创建以 Bootstrap 为主题的脚手架

标签 ruby-on-rails ruby twitter-bootstrap ruby-on-rails-4 twitter-bootstrap-rails

我正在尝试通过以下操作生成以 Bootstrap 为主题的脚手架:

  • gem 'twitter-bootstrap-rails' 行添加到 Gemfile 的末尾并运行 bundle install

  • 运行 rails generate bootstrap:install staticdocumentation 中所述

  • 将数据库帐户详细信息(用户名和密码)放入 database.yml 文件的“默认”部分并运行 rake db:create

  • 运行rails g scaffold Purchase company_name:text product_name:text contact_person:text email:text comment:text

  • 运行 rake db:migrate

  • 运行 rails g bootstrap:themed Purchases

每个命令都返回 0,所以我重新启动了一个网络服务器并转到 127.0.0.1:3000/purchases,但看起来它根本没有使用 twitter bootstrap:

enter image description here

purchases/index.html.erb

<h1>Listing purchases</h1>

<table>
  <thead>
    <tr>
      <th>Company name</th>
      <th>Product name</th>
      <th>Contact person</th>
      <th>Email</th>
      <th>Comment</th>
      <th colspan="3"></th>
    </tr>
  </thead>

  <tbody>
    <% @purchases.each do |purchase| %>
      <tr>
        <td><%= purchase.company_name %></td>
        <td><%= purchase.product_name %></td>
        <td><%= purchase.contact_person %></td>
        <td><%= purchase.email %></td>
        <td><%= purchase.comment %></td>
        <td><%= link_to 'Show', purchase %></td>
        <td><%= link_to 'Edit', edit_purchase_path(purchase) %></td>
        <td><%= link_to 'Destroy', purchase, method: :delete, data: { confirm: 'Are you sure?' } %></td>
      </tr>
    <% end %>
  </tbody>
</table>

<br>

<%= link_to 'New Purchase', new_purchase_path %>

为什么?我究竟做错了什么?我该如何解决?

顺便说一句,我正在使用 Ruby on Rails 4.1.4。

最佳答案

试试这些:

  1. 确保 <table>标记具有 Bootstrap 所需的类。例如:<table class="table table-striped"> .

  2. 此外,脚手架生成的样式在 app/assets/stylesheets/scaffolds.scss 中可能会干扰。移除它们,看看会发生什么。

正如@anusha 在评论中所说,记得到 use the singular form当你运行发电机时。例如:rails g bootstrap:themed Purchase , 不是 Purchases .

关于ruby-on-rails - 无法在 Ruby on Rails 中创建以 Bootstrap 为主题的脚手架,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25990375/

相关文章:

ruby-on-rails - 在 Rails View 中查找模式并替换为链接的正确方法

ruby-on-rails - rails 的 activerecord 将数据存储到错误的表中

html - 如何将文本放在图像卡头 bootstrap 4 上

javascript - HTML 属性中的 Vue.JS 数据

html - 如何根据帧大小定位div位置?

ruby-on-rails - Ruby on Rails 中的缩小和放大

ruby-on-rails - 如何使用Cucumber/Capybara测试多个文件上传?

ruby-on-rails - 使用 rabl-rails 设置 rails-api gem

ruby-on-rails - 如何显示来自rails本地项目文件夹的图像?

ruby - seed 会在不同的 Ruby 中生成相同的随机序列吗?