我正在尝试通过以下操作生成以 Bootstrap 为主题的脚手架:
将
gem 'twitter-bootstrap-rails'
行添加到Gemfile
的末尾并运行bundle install
运行
rails generate bootstrap:install static
如 documentation 中所述将数据库帐户详细信息(用户名和密码)放入
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:
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。
最佳答案
试试这些:
确保
<table>
标记具有 Bootstrap 所需的类。例如:<table class="table table-striped">
.此外,脚手架生成的样式在
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/