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.

Advertisements

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.

Chapter 5 of Michael Hartl’s guide

I’m working on Chapter 5 of the Michael Hartl guide Ruby on Rails Tutorial and I have this error when running the rails server:

undefined method `full_title'

On this line of code in the application.html.erb page:

 <title><%= full_title(yield(:title)) %></title>

Found a solution on StackOverflow that solved the error:

def full_title(page_title)
  base_title = "Ruby on Rails Tutorial Sample App"
  if page_title.empty?
    base_title
  else
    "#{base_title} | #{page_title}"
  end
 end

I had to define the full_title method in the application_helper.rb page. (Why the helper page?) And then add this to the application_controller.rb page:

include ApplicationHelper

Source: http://stackoverflow.com/questions/23630949/undefined-method-full-title