【问题标题】:Unable to create bootstrap-themed scaffold in Ruby on Rails无法在 Ruby on Rails 中创建引导主题的脚手架
【发布时间】:2014-09-23 08:28:26
【问题描述】:

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

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

  • 按照documentation 中的说明运行rails generate bootstrap:install static

  • 将数据库帐户详细信息(用户名和密码)放在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 引导程序:

购买/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 顺便说一句。

【问题讨论】:

  • 您是否为application 生成了布局?
  • @mccannf 我该怎么做?通过运行命令 rails g bootstrap:layout [LAYOUT_NAME]?
  • @FrozenHeart 将此命令更改为 rails g bootstrap:themed Purchasesrails g bootstrap:themed Purchase,因为您需要将主题应用于您的模型
  • @anusha 也不行
  • Yes rails g bootstrap:layout application 并确认您要覆盖现有布局。 如果您想在整个应用程序中使用引导程序。

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


【解决方案1】:

试试这些:

  1. 确保 &lt;table&gt; 标记具有 Bootstrap 所需的类。例如:&lt;table class="table table-striped"&gt;

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

正如@anusha 在评论中所说,运行生成器时请记住use the singular form。例如:rails g bootstrap:themed Purchase,而不是Purchases

【讨论】:

  • 删除 scaffolds.css 对我有用。非常感谢。
猜你喜欢
  • 1970-01-01
  • 2018-06-23
  • 2014-07-19
  • 2016-05-21
  • 2021-09-18
  • 1970-01-01
  • 2015-03-03
  • 2013-11-06
  • 2012-06-03
相关资源
最近更新 更多