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

How to create links in Rails

Creating links can be confusing if you are just starting to learn Rails. It is important to understand how your views, controllers, and routes are connected.

If you already have an app you are working on, simply type:

$rake routes

This command will let you see all your routes, how your views connect to your controller, their URLs, and how to link them in your HTML.erb file.

For example, this is mine:
rake routes rails

The ‘Prefix’ column contains the name of the link path that you will use.

The ‘Verb’ column tells you what HTTP actions are connected to each path:

 REST verb GET POST PUT DELETE
Action show create update destroy

The ‘URI Pattern’ column is the URL link

The ‘Controller#Action’ column gives you the name of the controller and the name of the method action connected with the page.

Taking the above information, we can open our ‘views/articles/index.html.erb’ page and start adding links!

Before you start, it is important to understand the difference between <% and <%=. The difference is:

  • <%..%> is for items you DO NOT want to appear in the view (like if statements and iterations).
  • <%=..%> is for items you DO want to appear in the view (like images and links).

To create a link in your html.erb file, you can follow this example:

<%= link_to "Text to show", model_instance %>

It will generate html that looks like this:

<a href="http://www.url.com/model_instance">Text to show</a>

Let’s create our own using the routes listed in our $rake routes using the above example.

<% link_to "New Article", new_article_path %>

The HTML for the link will look like so:

<a href="/articles/new">New Article</a>

To add a class to the link, just include it at the end:

<% link_to "New Article", new_article_path, class: "btn btn-default" %>

To add an image, use the following code recipe:

<%= image_tag('image.jpg') %>

Added Stripe gem to Rails app

Part VII of Codermanual is broken into three different sections. I’ve just completed the first two and am extremely excited about how my Rails app is coming along! We integrated Stripe, Devise, and Figaro gems into our app to add secure, authentic credit card payment to our membership site.

  • To use Stripe, you will need to sign up for a free account on their website: https://stripe.com/ 
  • Devise is an authentication gem. Read more about how to integrate it into your Rails app here.
  • Figaro helps you securely configure your Rails application.

Web application views

The home page:
heroku codermanual app

Alert for user sign-out:
Unnamed QQ Screenshot20150819055708

The sign-up screen for the Pro account:
pro account rails application

The sign-up screen for the Basic account:
basic account rails app

Icons | Gradients | Asset Pipeline

I’ve just completed the first part of Part VII of Rob Dey’s Codermanual course! He recommended some great resources for styling your website and improving site loading speed.

This is what my Rails app looks like so far, after completing the first part of Part VII:
codermanual saas


Font Awesome

If you want to add icons to your website, you can go to Font Awesome where there are tons of free pre-made icons. You can resize the icons, add them to a drop-down menu, and also add animations to the icons.

You can read their Getting Started page here to learn how to integrate it into your Rails app.


UIGradients

UI Gradients Color Design
A great website for getting CSS codes for pre-made color gradients. The website has a beautiful layout, with easy navigation. Click on the gradient you fancy and check out the CSS code. Simply copy and paste into your project!


Asset Pipeline

The asset pipeline in Ruby on Rails combines all your CSS files into one file, and all your JavaScript files into one file. Compressing them for faster loading speeds. In Rails 4, the asset pipeline is automatically added in your Gemfile under:

gem 'sass-rails'
gem 'uglifier'
gem 'coffee-rails'

If you don’t want your Rails application to automatically load the asset pipeline feature, you can just type this when creating a new Rails app:

$ rails new appname --skip-sprockets

Read more here: http://guides.rubyonrails.org/asset_pipeline.html


PageSpeed Insights

Enter your website URL here to check how fast your site loads on both mobile and desktop. Google will recommend what improvements you should make as well as let you know what you are doing right.
pageinsights google

Ruby on Rails Resources

Ruby:

https://www.ruby-lang.org/en/news/2013/12/25/ruby-2-1-0-is-released/

Rails:

http://guides.rubyonrails.org/4_0_release_notes.html

Rails Installation Guide:

http://railsinstaller.org/en
http://guides.railsgirls.com/install/
http://installfest.railsbridge.org/installfest/ I used this one to install on my Windows OS because I attended a RailsBridge event. I found it easy to follow. 

Ruby Gems:

https://rubygems.org/

Bundler:

http://bundler.io/
Bundler provides a consistent environment for Ruby projects by tracking and installing the exact gems and versions that are needed.

Learn Ruby:

TryRubyhttp://tryruby.org/levels/1/challenges/0 Really fun way to get introduced to the language. Great layout&design and user friendly.
Ruby on Codecademy: https://www.codecademy.com/tracks/ruby Very well written and easy to follow.
Ruby Programming on Odin: http://www.theodinproject.com/ruby-programming
Ruby Monk: http://rubymonk.com/learning/books/1-ruby-primer
Ruby the hard way: http://learnrubythehardway.org/book/ It really is hard. Especially if you don’t have a programming background.
Ruby in 100 minutes: http://tutorials.jumpstartlab.com/projects/ruby_in_100_minutes.html
Chris Pinehttps://pine.fm/LearnToProgram/chap_01.html
Master Ruby blockshttp://mixandgo.com/blog/mastering-ruby-blocks-in-less-than-5-minutes
Bastards book of Rubyhttp://ruby.bastardsbook.com/toc/
Ruby Newbie Odin Gisthttps://gist.github.com/brianllamar/11261930

Learn Rails:

Rails for Zombies: http://railsforzombies.org/ Really excellent lessons. Read more here.
Tech Talent South Rails Beginner Lesson:
http://techtalentsouth.slides.com/techtalentsouth/zero-to-heroku-workshop?token=r_LQ9_iu#/
Michael Hartl’s Tutorial: https://www.railstutorial.org/book/beginning
Ruby on Rails on Odin: http://www.theodinproject.com/ruby-on-rails

Ruby Help

http://ruby-doc.org/
https://www.codecademy.com/glossary/ruby/

Blogs:

http://www.jamesfend.com/learned-ruby-rails-12-weeks-launch-freelancify
http://www.codenewbie.org/blogs/ruby-roundup-1
http://www.smashingmagazine.com/2009/03/getting-started-with-ruby-on-rails/

Atlanta Ruby Users Group:

http://www.atlrug.com/

Jobs:

https://toprubyjobs.com/
https://www.jrdevjobs.com/jobs

Ruby Regular Expression Editor:

http://www.rubular.com/

Rails for Zombies | Code School

I just completed the Rails for Zombies by Codeschool. It’s a FANTASTIC way to learn how Rails 4 works. The professor Gregg Pollack is great at explaining the code and how models are connected to controllers to views. The course Rails for Zombies Redux is free, includes 5 lessons, and follows the following structure: video lesson, 4-5 exercises to practice what you learn, wrap-up video.

There’s exercises after every video lesson that let you practice what Gregg explains in the video so you can apply what you learned. I highly recommend watching the video lessons more than once and have a pen and paper in hand (or whatever you use to take notes) to write down his clear explanations.

Here are some screenshots:

ruby for zombies

rails for zombies

rails for zombies codeschool

After completing the course, you can add a completion badge to your LinkedIn profile. I highly recommend this course to anyone learning Rails, and especially for before tackling the Hartl tutorial.

Sandi Metz

Sandi Metz(http://www.sandimetz.com/) at the Atlanta RailsConf 2015 talking about object-oriented design: https://youtu.be/OMPfEXIlTVE

Looks at Ruby code, how to simplify and reduce the amount of code you write.

Sandi Metz wrote a book called Practical Object-Oriented Design in Ruby.
A description of what the book is all about and how it’s changed the way people learn to code:

Practical Object-Oriented Design in Ruby (POODR) is a programmers tale about how to write object-oriented code. It explains object-oriented design (OOD) using realistic, understandable examples.   POODR is a practical, readable introduction to how OOD can lower your costs and improve your applications.

POODR will help you:

  • Decide what belongs in a single class
  • Avoid entangling objects that should be kept separate
  • Define flexible interfaces among objects
  • Reduce programming overhead costs with duck typing
  • Successfully apply inheritance
  • Build objects via composition
  • Design cost-effective tests
  • Craft simple, straightforward, understandable code

If your code is killing you and the joy is gone, POODR has the cure.

Read more or purchase here: http://www.sandimetz.com/products/

Codermanual – Part V finished

I’ve just finished Part V of Codermanual, the JavaScript & jQuery section. It was an oversimplification of the language, I feel, but the way it was explained, really helped me wrap my head around how programming languages work. The amount of information in this part was overwhelming, but I feel confident now that I can handle JavaScript.

I had tried to learn JavaScript on my own back in April but I was using Codecademy at that time and I think their JavaScript tutorial was way too advanced. Everything went over my head. It was my first time learning an object-oriented programming language. Around the same time, I kept hearing a lot about Ruby and Ruby on Rails so I tried Codecademy’s Ruby course instead and found it much easier to grasp so I stuck with it and am now working on Michael Hartl’s Ruby on Rails tutorial.

I’m halfway through and realizing that there are still many things about Ruby that I have questions about, so I’m going to pause Hartl’s tutorial as well as Codermanual and do The Odin Project’s Ruby Programming course (which is also free!).

The more I learn, the more I realize how little I know.

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.