简体   繁体   中英

Simple form bootstrap for rails 4

I'm using 'bootstrap-sass' and 'simple_form' gems on Rails 4. When I run this generator: rails g simple_form:install --bootstrap I get a message that says:"Be sure to have a copy of the Bootstrap stylesheet available on your application, you can get it on http://twitter.github.com/bootstrap ."

Why do I need a copy of the Bootstrap stylesheet and what is THE stylesheet? Doesn't the 'bootstrap-sass' gem handle that? I went to the link provided but got a 404 error. If anyone can kindly explain what I need to do it would be greatly appreciated! I am fairly new to Rails, so apologize in advance if it's not a very good question. Thank you!

Here is the real link to Bootstrap . Yes, the bootstrap-sass gem will include Bootstrap's javascript, CSS, and fonts into your application, just make sure you include them.

In your javascripts/application.js ( docs )

//= require bootstrap

Create a file, say master.css.scss and import the Bootstrap CSS and fonts like so ( docs ):

@import "bootstrap";

When you specified the extension --bootstrap when installing simple_form, you essentially said, hey I have bootstrap and want my forms to be styled the way bootstrap styles them. It will also add the appropriate HTML to the form and inputs to adhere to Bootstrap. So it automatically generated the file config/initializers/simple_form_bootstrap.rb . Now when you create a form using simple_form_for (please read their docs ..they are very extensive), it will be styled like Bootstrap.

So, to sum it up, you need Bootstrap if you want your forms to be styled and set up, with Bootstrap html and css, like Bootstrap forms . If you didn't want Bootstrap, you could have just ran the simple_form generator like this: rails generate simple_form:install .

when you ran this code:

rails g simple_form:install --bootstrap

you are integrating simple_form with bootsrap . and therefore, what the message is telling you is to add bootstrap to your stylesheets folder of your application. The stylesheet folder is where you keep your css files. Here is it's directory structure:

app/assets/stylesheets

bootstrap download comes with css , javascripts , and fonts folders. the bootstrap files inside the css folder will go under app/assets/stylesheets .

of course, if you are not using bootstrap in your project, then you are running the wrong generator. you should simply run:

rails generate simple_form:install

and not append --bootstrap to the generator.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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