Friday, August 17, 2012

Lynda.com Ruby On Rails 3 Essential Training



I am following lynda.com's tutorial, Ruby on rails 3 essential training.

The video had me create a new rails app with rails new simple_cms -d mysql

What this does is to create a new rails app, specifying mysql as the default database. Other RoR tutorials that I have followed does not specify -d mysql, and uses SQLite3.

I then run rails generate controller demo index to get a controller and views. This time though, after I run rails s on my terminal, then go to localhost:3000/demo/index, I get this error message.


According to the instructional video, this error had something to do with rails 3 configuration.

I did not get this error when following a different Ruby on Rails Tutorial. I think this error has more to do with mysql. To fix this issue, I have to create a database for this app in mysql, then make sure the app and the mysql database are "talking to each other".

Going back to the terminal, I type mysql -u root -p to access mysql.

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
+--------------------+
2 rows in set (0.00 sec)

mysql> create database simple_cms_development;
Query OK, 1 row affected (0.00 sec)

mysql> show databases;
+------------------------+
| Database               |
+------------------------+
| information_schema     |
| mysql                  |
| simple_cms_development |
+------------------------+
3 rows in set (0.00 sec)

mysql> GRANT ALL PRIVILEGES ON simple_cms_development.*
    -> TO 'simple_cms'@'localhost'
    -> IDENTIFIED BY 'mypassword'
    -> ;
Query OK, 0 rows affected (0.02 sec)

mysql> SHOW GRANTS FOR 'simple_cms'@'localhost';
+-------------------------------------------------------------------------------------------------------------------+
| Grants for simple_cms@localhost                                                                                   |
+-------------------------------------------------------------------------------------------------------------------+
| GRANT USAGE ON *.* TO 'simple_cms'@'localhost' IDENTIFIED BY PASSWORD '*7FA9214D65F7EE1E3E91DC122D9EF345C09EF9F0' |
| GRANT ALL PRIVILEGES ON `simple_cms_development`.* TO 'simple_cms'@'localhost'                                    |
+-------------------------------------------------------------------------------------------------------------------+
2 rows in set (0.00 sec)



To test if this works, I log out of mysql, then log back in again...

mysql> exit
Bye
j@ime:~/arails/simple_cms$ mysql -u simple_cms -p simple_cms_development
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 46
Server version: 5.1.63-0ubuntu0.11.10.1 (Ubuntu)

Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> SHOW TABLES;
Empty set (0.00 sec)

The tutorial then had me go back to the application's root folder, in this case, ~/arails/simple_cms, then I type in rake db:schema:dump.

This command, if I understood correctly, connects this rails app to the mysql database that I created.

Before I do rails s, I go into app/config and open routes.rb. On the second line, I add...
get 'demo/index' do
end

...save the file and close it, cd back to the app's root folder, then run rails s. On the navigation bar, I type in ,code>localhost:3000/demo/index

I now have...


It is now 11.51pm. Time for bed.

1 comment:

  1. Great site for these post and i am seeing the most of contents have useful for my Carrier.Thanks to such a useful information.Any information are commands like to share him.
    PEGA Training in Chennai

    ReplyDelete