Access denied for user ‘root’@’localhost’ (using password: NO) OR ERROR 1045 (28000): Access denied for user ‘root’@’localhost’ (using password: NO)

Access denied for user 'root'@'localhost' (using password: NO)


ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)

This is the steps, what works for me sudo service mysql stop cd /usr/bin/ sudo mysqld_safe --skip-grant-tables sudo service mysql start I hope it help..!!!!!!!1

Manual active record db connection

Guy’s quick tour, how to connect standalone ruby file to mysql datababase. You can follow steps to understand procedure OR clone my working sample example active recored connection

1. Install relevant gems.
sudo gem install activerecord
sudo gem install yaml_db
sudo gem install logger

2. Create a ruby file and add below code.

require ‘rubygems’
require ‘active_record’

:adapter => ‘mysql’,
:database => ‘test’,
:username => ‘root’,
:password => ”,
:host => ‘localhost’)

when we run this file from rails console it should run without any error and output.

3. Now create table LOCATIONS in test database and insert some row.

mysql> create table locations(name varchar(100), city varchar(100));
Query OK, 0 rows affected (0.60 sec)

mysql> show tables;
| Tables_in_test |
| locations |
1 row in set (0.28 sec)

mysql> insert into locations(name,city) values(‘Sanyam’,’Bettiah’);
Query OK, 1 row affected (0.12 sec)

mysql> insert into locations(name,city) values(‘Sanyam’,’Bettiah’);
Query OK, 1 row affected (0.21 sec)

mysql> select * from locations;
| name | city |
| Ankit | Asansol |
| Sanyam | Bettiah |
2 rows in set (0.00 sec)

4. Add ruby class and inherit ActiveRecord::Base, So we can perform database operation.

class Location < ActiveRecord::Base

5. Add initialize action to access database and execute some command.

class Location < ActiveRecord::Base

def initialize
p 'Tables details'
p Location

p 'Count no of rows in table'
p Location.count


6. Run ruby file from command line, it supposed to display

pravinmishra@ubuntu:~/workSpace/RUBY_CODE/active_record_connection/lib$ ruby main.rb
“Tables details”
Location(name: string, city: string)
“Count no of rows in table”

that’s it.

Addition we can separate data configuration in different file and add logger to display sql query OR errors if any. I did all this two setups in active recored connection , You can take a look. 🙂


Rails link_to, link_to_if and link_to_unless

1. link_to
This is basic syntax to link other urls and actions.whivh creates a link tag of the given name using a URL created by the set of options.

link_to ‘Alter Challenge’, edit_challenge_path(@challenge)

2. link_to_if
This link_to helper create a link tag of the given name using URL only under certain circumstances,otherwise only the name is returned.

link_to_if user_logged_in?, “Create Challenge!”, new_challenge_path

Sometimes, it become irritating when user trying to do create challenge but link not working for him without having a clue how to.
Fortunately Action View provides a solution:

link_to_if user_logged_in?, “Create Challenge!”, new_challenge_path do
link_to “Log in to create challenge”, new_user_session_path

The block is executed in case the condition is not met. So if user aren’t logged in, We give them a hint how to create challenge.

2. link_to_unless
The counterpart to link_to_if is link_to_unless. You can use the simple version that will either render a link or just text.

link_to_unless user_signed_in?, “Login”, new_user_session_path

advanced version using a block:

link_to_unless user_signed_in?, “Login”, new_user_session_path do
link_to “Create Challenge!”, new_challenge_path


Sometimes we come to scenario, we need to find out what the current page is. The best I could do was this:

1. current_page?(options)

Will return true if the current request URI was generated by the given options.
Let’s say we’re in the /shop/checkout?order=desc action.
current_page?(:action => ‘process’)
# => false

current_page?(:controller => ‘shop’, :action => ‘checkout’)
# => true

2. request.path_parameters

this should return a hash along the controller and action.
{:action => ‘my_action’, :controller => ‘my_controller’}