4

I'm trying to generate a bootstrap-themed scaffold via the following actions:

  • Add gem 'twitter-bootstrap-rails' line to the end of the Gemfile and run bundle install

  • Run rails generate bootstrap:install static as stated in the documentation

  • Place the DB account details (username and password) to the "default" section of database.yml file and run rake db:create

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

  • Run rake db:migrate

  • Run rails g bootstrap:themed Purchases

Every command returns 0, so I restarted a web-server and go to the 127.0.0.1:3000/purchases, but it looks like it doesn't use twitter bootstrap at all:

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 %>

Why? What am I doing wrong? How can I fix it?

I'm using Ruby on Rails 4.1.4 btw.

FrozenHeart
  • 19,844
  • 33
  • 126
  • 242
  • Did you generate the layout for `application`? – mccannf Sep 23 '14 at 08:37
  • @mccannf How can I do it? By running the command rails g bootstrap:layout [LAYOUT_NAME]? – FrozenHeart Sep 23 '14 at 08:39
  • 1
    @FrozenHeart change this command to `rails g bootstrap:themed Purchases` to `rails g bootstrap:themed Purchase` as you need to apply theme to your model – anusha Sep 23 '14 at 08:41
  • @anusha It doesn't work too – FrozenHeart Sep 23 '14 at 08:43
  • Yes `rails g bootstrap:layout application` and confirm you want to overwrite the existing layout. **If** you want to use bootstrap throughout the app. – mccannf Sep 23 '14 at 08:44
  • @mccannf Ok, I'll try it, but why do I need it? – FrozenHeart Sep 23 '14 at 08:50
  • @FrozenHeart change the gem like this and `gem 'twitter-bootstrap-rails', :git => 'git://github.com/seyhunak/twitter-bootstrap-rails.git'` and try generate bootstrap theme again `rails g bootstrap:themed Purchase` – anusha Sep 23 '14 at 08:54
  • @FrozenHeart. Hmm, actually you should not need it if you generated the theme for Bootstrap. Can you confirm that `app/assets/javascript/application.js` and `app/assets/stylesheets/application.css` contain requires for bootstrap? Did the generate theme for Purchases overwrite all the `.erb` files? There is something wrong here. Did you add the `therubyracer` gem as well? – mccannf Sep 23 '14 at 09:11
  • There should be no need to override the application layout. Focus on the table styles. (See my answer below.) – jkdev Jan 26 '16 at 01:06

1 Answers1

1

Try these:

  1. Make sure the <table> tag has the class(es) required by Bootstrap. For example: <table class="table table-striped">.

  2. Also, the scaffold-generated styles in app/assets/stylesheets/scaffolds.scss might be interfering. Remove them and see what happens.

And as @anusha said in a comment, remember to use the singular form when you run the generator. For example: rails g bootstrap:themed Purchase, not Purchases.

Community
  • 1
  • 1
jkdev
  • 11,360
  • 15
  • 54
  • 77