twitter-bootstrap-rails gem workflow - ruby-on-rails

How do I use the twitter-bootstrap-rails gem in my Rails 3.2.1 app? What is the workflow?
After I do:
rails g bootstrap:layout [LAYOUT_NAME] [*fixed or fluid] [options]
what do I do next? Do I just copy and paste the generated code into my view? Do I do this for every view? If so, how is doing
rails g bootstrap:themed [RESOURCE_NAME] [LAYOUT] [options]
any different?
Do you guys even use the rails generators?
Thanks

I'm the author of twitter-bootstrap-rails gem. I'll give you a quick walktrough to how to install and use twitter-bootstrap-rails.
Ruby stack;
(Ruby 1.9.3, Rails 3.1 or Rails 3.2 is required. Use RVM to get started)
After bundling gem to Gemfile by;
gem 'twitter-bootstrap-rails'
bundle install
Run install generator
rails g bootstrap:install
(it will includes Twitter Bootstrap to your app's asset pipeline)
Run layout generator
rails g bootstrap:layout application fixed
(it will generates layout for you, by default application.html.erb and fixed layout will generates)
Run themed generator (optional);
rails g scaffold post title:string description:text
(this step uses Rails generators to create CRUD stuff for you)
rake db:migrate
(migrating to database)
rails g bootstrap:themed posts
(Twitter Bootstrap compatible styling for your 'posts' views and form)
Also there is detailed documentation to install, usage and generators, coffeescript etc.
https://github.com/seyhunak/twitter-bootstrap-rails.

There is a RailsCasts tutorial that is a great starting point:
http://railscasts.com/episodes/328-twitter-bootstrap-basics

Run:
rails new APPLICATION -m anyfile.rb
anyfile.rb
gem "therubyracer"
gem "less-rails"
gem "twitter-bootstrap-rails"
generate("scaffold", "Post title:string content:text")
rake("db:create")
rake("db:migrate")
generate("bootstrap:layout", "application fluid")
generate("bootstrap:install")
generate("bootstrap:themed", "posts")
git :init
git :add => "."
git :commit => "-m First commit!"

Related

Missing views generator for Rails; resulting in error 'Could not find generator...'

I'm trying to run the following command after installing the Devise gem:
Gunface:/ Jacob$ cd ~/12-in-12/Forum
Gunface:Forum Jacob$ rails g devise:views
I'm getting this error:
Could not find generator 'devise:views'. Maybe you meant 'assets', 'scss:assets' or 'js:assets'
I've run the helper, and the views generator is in fact missing:
Please choose a generator below.
Rails:
assets
controller
generator
helper
integration_test
jbuilder
job
mailer
migration
model
resource
scaffold
scaffold_controller
task
I have definitely followed the instructions that appear after installing Devise.
So, is there a way to create a views generator in a Rails app? I have no idea how to fix this, and I haven't found a similar question that helped resolve this problem.
Add the Devise gem to Gemfile, then specify the ruby version in line 2 with
ruby '2.2.2'
Save the Gemfile
Run
$ bundle install
Run
$ rails g devise:views

bootstrap:themed error - not generating the proper views

Rails: 3.2.6
twitter-bootstrap-rails (2.2.3, 2.1.0)
I did the following:
rails generate bootstrap:install static -s
I then generated the scaffolding for certification as follows:
rails generate scaffold certification id:integer user_id:integer name:string description:string location:string status:string --skip-stylesheets -s
Then I tried to generate the twitter bootstrap views as follows:
rails generate bootstrap:themed certifications -f -s
Which gave me the following error:
undefined method `fields' for #<Class:0x007fe5e7282060>
and no changes were made to the certifications views. Any ideas?
I had similar issues, because I was working with a mix of mongoid and active records. I guess somehow there were conflicts while using the generator and it couldn't find the fields method anymore.
The solution for me was a reinstall twitter-bootstrap-rails gem with the following:
gem "twitter-bootstrap-rails", :git => 'https://github.com/seyhunak/twitter-bootstrap-rails.git'
Also, do not forget to run
rake db:migrate
after your
rails generate scaffold ...
For those working with mongoid, additional tip: everytime I have to generate a scaffold for an active record, I comment:
#gem "mongoid", "~> 3.0"
#gem "composite_primary_keys"
Then, generate, then uncomment

Remove twitter bootstrap from Rails (added via twitter-bootstrap-rails)

How do I remove the twitter-bootstrap-rails gem and all the assets and configurations from my rails app?
I installed it with
bundle install
#and
rails g bootstrap:install
Could you just do this :
rails destroy bootstrap:install
and remove it from your Gemfile?

Having trouble finding a generator in Rails 3.1 for gem installed using git as source

First, I am using Rails 3.1.
I have installed the activemessaging gem from git.
This is in my Gemfile:
gem 'activemessaging', :git => 'git://github.com/kookster/activemessaging.git'
bundle show activemessaging outputs:
/Users/ken/.rvm/gems/ruby-1.9.2-p180#cMoM/bundler/gems/activemessaging-037532e0eb69
and an ls of .../activemessaging-037532e0eb69 shows
a13g_test_harness filter processor tracer
Yet if I run one of the generators I get a generator not found message. Running rails g does not show any generators for activemessaging.
Does anyone know why these generators are not found?

Couldn't find 'rspec' generator

I'm trying to install RSpec as a gem after having it installed as a plugin. I've gone ahead and followed the directions found here http://github.com/dchelimsky/rspec-rails/wikis for the section titled rspec and rspec-rails gems. When I run ruby script/generate rspec, I get the error Couldn't find 'rspec' generator. Do only the plugins work? If so, why do they even offer the gems for rspec and rspec-rails? I'm running a frozen copy of Rails 2.1.2, and the version of rpsec and rspec-rails I'm using is the newest for today (Nov 7, 2008) 1.1.11.
EDIT Nov 12, 2008
I have both the rspec and rspec-rails gems installed. I've unpacked the gems into the vender/gems folder. Both are version 1.1.11.
Since RSpec has been become the default testing framework in Rails you no longer need to create spec docs via the rspec generators:
Rails 2 RSpec generator
rails generate rspec_model mymodel
Rails 3 RSpec generator
With RSpec as the default testing framework simply use Rails' own generators. This will construct all of the files you need including the RSpec tests. e.g.
$rails generate model mymodel
invoke active_record
create db/migrate/20110531144454_create_mymodels.rb
create app/models/mymodel.rb
invoke rspec
create spec/models/mymodel_spec.rb
Have you installed both rspec and rspec-rails gems?
script/generate rspec
requires rspec-rails gem to be installed.
For Rails 3 and rspec 2+
You must make sure you include 'rspec' and rspec-rails' in your Gemfile
Run Bundle Install
then run rails g rspec:install
If you are using rails 2.3 You need to use
ruby script/plugin install git://github.com/dchelimsky/rspec-rails.git -r 'refs/tags/1.3.3'
and then
ruby script/generate rspec
Is there supposed to be an 'rspec' generator? I've only used the following:
script/generate rspec_model mymodel
script/generate rspec_controller mycontroller
I've had this problem before, it boiled down to the version of RSpec I had not working with the version of Rails I was using. IIRC it was a 2.1 Rails and the updated RSpec hadn't been released as a gem. In fact, 1.1.11 is the gem I have, which would be the latest available (ignoring github gems), so I'm pretty sure that's exactly what my problem was.
I've taken to just using the head of master rspec with whatever version of Rails I happen to be on, it seems stable to me (and isn't going to break things in production, unless somehow a test broke with a false positive).
I do it with git using submodules, for example:
git submodule add git://github.com/dchelimsky/rspec.git vendor/plugins/rspec
git submodule add git://github.com/dchelimsky/rspec-rails.git vendor/plugins/rspec_on_rails
In case anyone is wondering about Rails 3 now,
this seems to do the trick for me:
http://github.com/rspec/rspec-rails/blob/29817932b99fc45adaa93c3f75d503c69aafcaef/README.markdown
I'm using rails 2.3.9. I started of trying to use the gem(s) but just couldn't get the generator for rspec to show up. Then I installed the plugin(s) using the instructions on https://github.com/dchelimsky/rspec/wiki/rails and that did the trick.
On Fedora 9 (OLPC) I did:
$ sudo gem install rspec
$ sudo gem install rspec-rails
Those got me to where I could run
$ ruby script/generate rspec
This worked for me, whereas the git instructions did not work.
If you are using bundler version 1.0.8 you should $ gem update bundler to a newer version 1.0.9.
I had the same symptons and updating bundler helped me out.
Now $ rails g is using gems defined in the Gemfile. Also I grouped my gems like this:
source 'http://rubygems.org'
gem 'rails', '3.0.3'
gem 'sqlite3-ruby', :require => 'sqlite3'
group :test, :development do
gem 'capybara', '0.4.1.1'
gem 'database_cleaner'
gem 'cucumber-rails'
gem 'rspec-rails', '~> 2.4'
gem 'launchy'
end
(Note that test gems are also in the :development group.)
Have a nice day :)
Lukas
If you type script/rails generate, the only RSpec generator you'll actually see is rspec:install. That's because RSpec is registered with Rails as the test framework, so whenever you generate application components like models, controllers, etc, RSpec specs are generated instead of Test::Unit tests.
Please note that the generators are there to help you get started, but they are no substitute for writing your own examples, and they are only guaranteed to work out of the box for the default scenario (ActiveRecord & Webrat).
https://github.com/rspec/rspec-rails
You might need to run bundle exec :
bundle exec rails g rspec:install
You'll need to do
sudo gem install cucumber-rails

Resources