A way to generate devise views that already include bootstrap CSS styling? - ruby-on-rails

This devise generator saves a mountain of work by making all the views necessary for authentication:
rails g devise:views
Can the views above be generated but with bootstrap styling already included? E.g. perhaps similar to how rails new has the css=bootstrap option.
Note: I realise that styling is necessarily opinionated, however, it wouldn't be a bad thing since it would be a time-saver.

Maybe you can use rails templates.
An example with bootstrap and devise: https://github.com/lewagon/rails-templates
Note: It might be specific to the Le Wagon setup but I believe you can use the same approach to tailor it to your needs.

This gem adds bootstrap views:
https://github.com/kroger/devise-bootstrap5
Just add these two gems to your gemfile and you're basically done.
...
gem "devise-i18n"
gem "devise-bootstrap5"
...

Related

How do I undo Rails template generation in Haml?

I installed a new gem to my Rails project - 'phrasing' - which has gem dependencies on multiple Haml gems. I need the gem (it is adding some phenomenal functionality to my project), and need the dependencies to be installed, but now when I run rails generate scaffold, all of the view templates are generated in Haml rather than ERB. I need views to continue to be generated in ERB.
I reviewed several previous StackOverflow articles, but most focus on converting TO Haml, and the answers around making sure that ERB is the default generator refer to removing lines from the config files, which are not there in my case (it appears that the gems are controlling the default layout format somehow).
(Note: While I appreciate that there may be several advantages to using Haml, and I might consider using it in a new project, I'd like to keep this one consistent, and it's already 80% finished in ERB.)
Turns out this was as simple as adding the following into class Application in the config/application.rb file:
config.generators do |g|
g.template_engine :erb
end
Still not sure why the manual override was necessary, but it is. This fixes it.

Remove Bootstrap from my simple_form gem after install?

I used a command to make the simple_form gem work well with bootstrap. I'm pretty sure it was:
$ rails g simple_form:install --bootstrap
But I've decided I'm not going to use Bootstrap as my Rails app will be mostly used with mobile phones. I'm going to go with jQuery mobile. I make use of both jQuery Mobile and Bootstrap in my app, at present, and they seem to be clashing sometimes in the use of class names. I'm just going to use jQuery Mobile which I think is sufficient. Any thoughts or useful articles on this would be handy.
So, what would be the command for undoing the above? I know it scattered a few files around the place in my app folder and I'd like to undo it to keep it clean. Thanks.
Run the following two commands:
rails d simple_form:install --bootstrap ## Destroy the existing configurations for simple_form
rails g simple_form:install ## Generate the clean configurations for simple_form
When you initially ran the generator for simple_form with --bootstrap option, it created bootstrap compatible configurations for simple_form. The changes that have been specifically made for bootstrap are spread across multiple files. It would be hard to cherry-pick them and remove unless you know exactly what needs to be removed and what to keep for simple_form.

How can I have Ruby on Rails output Bootstrap v3 scaffolding?

I'd like to be able to use Bootstrap 3 and Sass in my RoR project and have the scaffolding generator output Bootstrap 3 HTML. I'm using Ruby 2 with Rails 4.
Nothing too fancy - mostly just having the forms buttons have the appropriate CSS classes.
I've used the Rails Tutorial Sample App (ver 4) as a base which includes the bootstrap-sass gem - but when I use the generator the HTML does not have the proper bootstrap classes - for instance the buttons don't have the btn btn-default class.
I realize that the scaffolding is behaving as it was designed to, it is a base and is meant to be customized (or replaced) - but it seems like it should not be hard to also have the generated HTML be "Bootstrap Ready"
A related question had an answer where someone mentioned that editing the files in the directory lib/erb/scaffold like edit.html.erb - would override the default templates that Rails uses for scaffolding. I'm not opposed to that but I was hoping that there might be a something like a gem that already did this.
I like using the bootstrap-sass gem and I hope that there is a solution that would be compatible with it - I'd rather use scss than less
Seems like there should be several gems to do this.
I've had the same trouble but finally found this:
https://github.com/decioferreira/bootstrap-generators
It includes Bootstrap 3.1 and provides scaffolding and you can choose haml and scss as well as other options.
For example when I did rails g scaffold Link guid:string profile:string media_url:string
It automatically produced this:
EDIT FOR HEROKU USERS
I did have trouble pushing my app that is using bootstrap-generators (v3.1.1) to Heroku. Heroku was giving the error File to import not found or unreadable: bootstrap.scss
The fix turned out to be to modify the automatically generated bootstrap-generators.scss file. Change #import "bootstrap.scss"; to #import "bootstrap"; (eg just remove the extension).
NEW EDIT FOR HEROKU USERS
The new gem 3.1.1.1 fixes the bug. You no longer need to change #import "bootstrap.scss"; to #import "bootstrap"; in the bootstrap-geneerators.scss file.
If you need to customize your generated views more you can actually override the default views with your own.
Just put them in lib/templates/{erb|haml}/scaffold. You can see some example files here.
This may be what you're looking for http://railscasts.com/episodes/328-twitter-bootstrap-basics

How to apply bootstrap to existing rails file generated through scaffold?

through railscasts, I found http://railscasts.com/episodes/328-twitter-bootstrap-basics that with the
gem 'less-rails' (this is the gem https://github.com/seyhunak/twitter-bootstrap-rails)
I can use
rails g bootstrap:themed scaffold-name -f
which applies bootstap to various classes like table, buttons etc. This is amazing timesaver but I am not able to find this for SASS as I am using SASS for my rails app (I am using this gem https://github.com/thomas-mcdonald/bootstrap-sass)
IS there any way to apply bootstap to existing scaffold code as me doing this manually can take lot of time ? OR is there any easy way to put the classes in the .erb files ?
Thanks

Rails gem with CSS and javascript

I've got a simple rails gem (created using bundler) and I'd like to extend it by adding some CSS and javascript functionality. However, I'm unsure how to go about this and where to add the files. In particular, I need need more information on how it all fits together with the asset pipeline once it gets included in another project.
Can anyone give me the lowdown on how this works and either provide some simple examples or link to a tutorial? Literally 1 css and 1 js file is all I'm looking to include. Thanks.
You could write the gem as an engine. This allows you to have an app folder in the gem just as any Rails application would have. You can add models, views, controllers, assets etc.
Once you have it set up it's quite intuitive and it's a familiar way to create a gem if you're used to creating Rails apps.
This should get you started:
http://coding.smashingmagazine.com/2011/06/23/a-guide-to-starting-your-own-rails-engine-gem/

Resources