How to apply bootstrap to existing rails file generated through scaffold? - ruby-on-rails

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

Related

A way to generate devise views that already include bootstrap CSS styling?

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"
...

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.

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/

Divs instead of Tables in Rails generator

Is it possible to customize or find a gem that changes the behaviors of auto generating Tables in the views when I use rails scaffold and change it with Divs instead? Like cleaner templates, I'm using rayan's nifty generators but it uses tables instead of divs .
Any help would be highly appreciate .
Eqbal
I don't know of any such scaffold generator, but you can build one easily by taking Ryan's nifty generators as a starting point. You can modify it to your needs by following these steps:
Fork the repository on Github and clone it.
Change the file /rails_generators/nifty_scaffold/templates/views/erb/index.html.erb to fit your needs.
Commit and push your changes.
Add the newly created Gem to your Gemfile like this:
gem "nifty-generators", :gem => "https://github.com/[your_user]/nifty-generators.git"

can i "freeze the code" of activescaffold or rails_admin in rails?

i want to generate a complex scaffold and then remove the gems
is there a way to freeze the code that rails_admin or activescaffold generates so i can edit it myself ? (similar to how rails scaffold does it)
is there another gem that generates a more complex scaffold?
In active scaffold to alter a scaffold's views you use overrides.
This depends on what version of Rails you're running. If >2.1, you can specify gems explicitly in environment.rb using config.gem, and then run rake gems:unpack to freeze those gems into the vendor/gems folder. For >=3.0 use the Builder tool to freeze the gem.
If <= 2.1, then you could do the above step manually -- copy all of the ActiveScaffold gem code into a folder in vendor/plugins, and remove the gem itself. See earlier plugin-based versions of ActiveScaffold for guidance.
You can also do this only as needed. To customize views, create an app/views/active_scaffold_overrides folder, and copy any ActiveScaffold partials to customize there. They will automatically be used across your app -- no need to duplicate them into each view. To customize controller actions, create a controller named ActiveScaffold, and then have all other scaffold controllers inherit from this new ActiveScaffoldController. Now you have somewhere to override the actions themselves, and you can override helpers in the generated ActiveScaffoldHelper file too.

Resources