Solve Error in Windows Command: TZInfo::DataSourceNotFound

How to Resolve TZInfo::DataSourceNotFound Error

If you are using Windows to make Ruby on Rails apps and come across this error in your command prompt when trying to run the Rails server:

C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/tzinfo-1.2.2/lib/tzinfo/data_source.rb:182:in `rescue in create_default_data_source': No source of timezone data could be found. (TZInfo::DataSourceNotFound)
Please refer to http://tzinfo.github.io/datasourcenotfound for help resolving this error.

Add this to the Gemfile in your app:

gem 'tzinfo-data', platforms: [:mingw, :mswin]

Run $bundle install
And then run your Rails server again. $rails server

Advertisements

Integrating Bootstrap with Rails 4

Today’s project was incorporating Bootstrap into my Rails application.

To start, I redid this basic Ruby on Rails tutorial on Tech Talent South’s website. To make it more personal, I decided to make a list of movies instead of a list of random members. I followed this guide by Koren Leslie Cohen on how to change column names in a database. It’s a great, simple guide, but I found that when I changed  the :name and :age into :title and :release, respectively, they didn’t change across all my views so I still had to go in manually and change them, which to me, beats the purpose of using the rails g migration command. Not sure if there is a better way to do it, as I am still new to Rails, but will keep searching.

To incorporate Bootstrap, I downloaded Bootstrap and followed along with the Readme file included in the download package.

This is what I added to my Gemfile:

gem 'sprockets-rails', '>=3.0.0.beta1'
gem 'sass-rails', '>=5.0.3'
gem 'uglifier', '>= 1.3.0'
gem 'coffee-rails', '~> 4.1.0'
gem 'autoprefixer-rails'
gem 'bootstrap-sass', '~> 3.3.1'

In the guide, they recommended to add these two gems for SASS:
gem ‘bootstrap-sass’, ‘~> 3.3.4’
gem ‘sass-rails’, ‘>= 3.2’

But I kept getting errors when running ‘bundle install’ so I’m thinking these two gems are outdated. Could be because I had downloaded Bootstrap a couple months ago and my version of Bootstrap is older. So I had to go in and manually change the versions. This is where I found the latest version number for sass-rails.

If you come across the following error:

Bundler could not find compatible versions for gem "sprockets-rails"

Then you can go here to double check and see if your version of ‘sprockets-rails’ is compatible with your version of Ruby and Rails.

This is a great step-by-step guide on how to integrate Bootstrap 3.3 with Rails 4.2. After step 7, you can pick and choose what code you want to integrate into your site. Also refer to the CSS page on the Bootstrap home.

This is my final product: https://tts-sunsplat.c9.io/members (still a work in progress!)

Need to:
1. Add errors if no text in form fields.
2. Add movie descriptions to the ‘view’ page. (Maybe API?)
3. Add color.
4. Add images.

Resetting the Migration

$ bundle exec rake db:migrate

While working on Chapter 6 of the Michael Hartl Ruby on Rails tutorial, I kept getting a crazy long error. This is an example of that error:

== 20141129134103 CreateUsers: migrating ======================================
-- create_table(:users)
rake aborted!
StandardError: An error has occurred, all later migrations canceled:

Mysql2::Error: Table 'users' already exists: CREATE TABLE `users` (`id` int(11) auto_increment PRIMARY KEY, `name` varchar(255), `created_at` datetime, `updated_at` datetime) ENGINE=InnoDB/home/barry/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/activerecord-4.1.8/lib/active_record/connection_adapters/abstract_mysql_adapter.rb:303:in `query'
/home/barry/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/activerecord-4.1.8/lib/active_record/connection_adapters/abstract_mysql_adapter.rb:303:in `block in execute'
/home/barry/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/activerecord-4.1.8/lib/active_record/connection_adapters/abstract_adapter.rb:373:in `block in log'
...
/home/barry/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/activerecord-4.1.8/lib/active_record/migration.rb:621:in `block in say_with_time'
...
/home/barry/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/activerecord-4.1.8/lib/active_record/migration.rb:948:in `each'
...
/home/barry/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/rake-10.4.0/bin/rake:33:in `<top (required)>'
/home/barry/.rbenv/versions/2.1.2/bin/rake:23:in `load'
/home/barry/.rbenv/versions/2.1.2/bin/rake:23:in `<main>'
Tasks: TOP => db:migrate

The error was occurring because I had already created a table named Users. To solve this, I wanted to reset my database back to the original. I used

$ rake db:reset

and then ran

$ bundle exec rake db:migrate

and everything worked perfectly!


http://stackoverflow.com/questions/27202970/running-rake-dbmigrate-in-rails-fails-table-already-exists-using-mysql

rake db:migrate:down  # To have rails remove the table and keep in sync*

delete ('drop table users') the table in mysql and then re-run the migrations.

Use rake db:reset as indicated by jykim to drop the database.