Re: MySQL

This happens when I try and enter this code:

mysql depot_development <db/create.sql

BTW I am using Agile Web Development in Rails. 

However, when I tried to import the create.sql in Cocoa MySQL it worked no problem, would still like to know why it gave me that error.

Re: MySQL

You need to specify the username and pass when running the mysql command. Try:

mysql -u root -p depot_development <db/create.sql

Railscasts - Free Ruby on Rails Screencasts

Re: MySQL

why didn't it say that in the book?  is it because of:

grant all on depot_development. * to 'dave@localhost';

Did I need to specify my username there?

Re: MySQL

The book doesn't know your username and I guess it assumes the reader has previous knowledge of MySQL. Also some people have MySQL configured so it doesn't require you to specify a user name.

NickToye wrote:

grant all on depot_development. * to 'dave@localhost';

Did I need to specify my username there?

Well, you specified the username "dave" here. So yes, when you login to MySQL you'll need to specify the username "dave".

Railscasts - Free Ruby on Rails Screencasts

Re: MySQL

Ok, so if I typed"

grant all on depot_development. * to 'root@localhost';

I would just need to specify -u root

Re: MySQL

Yeah, the root probably already has access to it though.

Railscasts - Free Ruby on Rails Screencasts

Re: MySQL

right so in that case I needn't grant all in the command line as root already has access.

Re: MySQL

Yep, all you should need to do in the mysql command line is create the databases:

create database depot_development;
create database depot_test;
create database depot_production;

BTW, it looks like you are using the first edition of the book? You may want to get the 2nd edition which is updated for the latest version of Rails. It really is much better.

Railscasts - Free Ruby on Rails Screencasts

Re: MySQL

Yeah I've noticed some changes that have caused me some errors.  Some of them I have picked up on and some I haven't.

For instance:

When I am trying the login to the admin section and I go to login I get this error:

ArgumentError in LoginController#login

wrong number of arguments (1 for 0)
RAILS_ROOT: /Users/nicktoye/src/depot/public/../config/..

Application Trace | Framework Trace | Full Trace
#{RAILS_ROOT}/app/controllers/login_controller.rb:25:in `name'
#{RAILS_ROOT}/app/controllers/login_controller.rb:25:in `login'
Request

Parameters: {"user"=>{"name"=>"NickToye", "password"=>"millac"}}

Show session dump

Response

Headers: {"cookie"=>[], "Cache-Control"=>"no-cache"}

Re: MySQL

Can you post the code in the "login" action? I might be able to help with that.

Railscasts - Free Ruby on Rails Screencasts

Re: MySQL

the Login Controller?

class LoginController < ApplicationController
  layout "admin"
 
  def index
    @total_orders = Order.count
    @pending_orders = Order.count_pending
  end
 
  def add_user
    if request.get?
      @user = User.new
    else
      @user = User.new(params[:user])
      if @user.save
        redirect_to_index("User #{@user.name} created")
      end
    end
  end

  def login
    if request.get?
      session[:user_id] = nil
      @user = User.new
    else
      @user = User.name(params[:user])
      logged_in_user = @user.try_to_login
      if logged_in_user
        session[:user_id] = logged_in_user.id
        redirect_to(:action => "index")
      else
        flash[:notice] = "Invalid user/password combination"
      end
    end
  end

  def logut
  end

  def  delete_user
  end

  def list_users
  end
end

Re: MySQL

Here you are calling User.name instead of User.new (I think that's what you want anyway). Try this:

  def login
    if request.get?
      session[:user_id] = nil
      @user = User.new
    else
      @user = User.new(params[:user])
      logged_in_user = @user.try_to_login
      if logged_in_user
        session[:user_id] = logged_in_user.id
        redirect_to(:action => "index")
      else
        flash[:notice] = "Invalid user/password combination"
      end
    end
  end

I don't have the first edition with me so I can't look it up. Take a look in the book to make sure this is correct.

Railscasts - Free Ruby on Rails Screencasts

Re: MySQL

Cheers Ryan,

I may need to order the 2nd edition, and hope it won't fall out of date.

smile

Re: MySQL

Ordered.  smile