Error working through Agile!

Hi everyone,

I’m working my way thru the ‘Depot’ project from Agile Web D.
with Rails.

I got to the bit where I type:
ruby script/generate scaffold Product admin

And I get the following error:

error Before updating scaffolding from new DB schema, try creating a
table for your model (Product) ( on the last line ! )

Now I have followed everything as exactly as detailed and gone back and
triple checked everything, but I must have missed some simple point.

I created the database’s and tables with phpMyAdmin.

TIA - Dave P.

At 02:40 AM 6/6/2006, you wrote:

Hi everyone,

I’m working my way thru the ‘Depot’ project from Agile Web D.
with Rails.

me also, but i am using the second edition ebook.

I got to the bit where I type:
ruby script/generate scaffold Product admin

And I get the following error:

error Before updating scaffolding from new DB schema, try creating a
table for your model (Product) ( on the last line ! )

the ebook i have does not have that step (although it is shown here:
http://developer.apple.com/tools/rubyonrails.html, but i am on a
windoze box)), instead it says to do:

     class AdminController < ApplicationController
             scaffold :product
     end

and restart the server and look at http://localhost:3000/admin, but this
gets:

ActionController: Exception caught
routing error
Recognition failed for “/admin”

Now I have followed everything as exactly as detailed and gone back and
triple checked everything, but I must have missed some simple point.

I created the database’s and tables with phpMyAdmin.

this edition uses migrate, which makes the tables.

thanks


vice-chair http://ocjug.org/

Hi Ray,

Thanks for the feedback. Yes you are right I had printed out an earlier
version a few weeks ago, but the 2nd Ed is quite different.

I checked out that section and it tells you to type:
mysql -u root depot_developement to test to see if you can connect and I
get an error:
Error 1045 Access denied for user root@localhost using password NO

But phpMyAdmin works fine with the root login, so I’m a little confused
as to why that is happening ?

Cheers, Dave P.

Just tried again, but still no luck.

I worked through all the possible issues that may cause ‘rake
db:migrate’ not to work, ( listed in the 2nd edition of the book ! ) but
none seem to work.

I’ll keep trying, but if anyone has any thoughts I’d appreciate any
help.

cheers, Dave

I guess I’m working with the 1st edition e-book (Printed July 2005).
Being
a complete an utter newbie (basically installed Rails this past Sunday)
I’ll
take a stab at a few suggestions. First, for the sake of staying with
the
book code and not deviating since it’s painful enough when there are
typos
or errors in the book I’d use the mySQL cl interface as well as (in my
edition) keep the flat create.sql file under /db/create.sql. Also
since I
didn’t see it mentioned in the thread make sure the config/database.yml
file
is configured correctly. You should be working in the depot_development
databse.
Good luck
Stuart

Another note - I just checked into the 2nd edition - is it still in beta
?
Looks like pub date isn’t until 9/2006. In that case I don’t feel so
bad
about having the 1st.

Stuart

Dark A. wrote:

Another note - I just checked into the 2nd edition - is it still in beta
?
Looks like pub date isn’t until 9/2006. In that case I don’t feel so
bad
about having the 1st.

Stuart

2nd edition is very different from the first. Many new improvements to
Rails and examples reflect that. I would recommend you get the newer
version.

I’m thinking about it but am I correct in my understanding that it’s in
beta
?

Stuart

Correction:
Sorry the mysql command line does work OK.
I need to start again with the new second edition and see how I go.
cheers, Dave

Dave P. wrote:

Hi Ray,

Thanks for the feedback. Yes you are right I had printed out an earlier
version a few weeks ago, but the 2nd Ed is quite different.

I checked out that section and it tells you to type:
mysql -u root depot_developement to test to see if you can connect and I
get an error:
Error 1045 Access denied for user root@localhost using password NO

But phpMyAdmin works fine with the root login, so I’m a little confused
as to why that is happening ?

Cheers, Dave P.

How much difference is there ? Not as concerned about price but more
about
starting on one book, dropping it to move on to another. The Depot
sections
aren’t as important to me as the “Rails Framework” part.
And :), does the second edition cover 1.8.4 ? or how far back version
wise
is it ?

Stuart

Just bought 1st edition myself :-\

Dark A. wrote:

I’m thinking about it but am I correct in my understanding that it’s in
beta ?

Yes, new versions are being released periodically. Your purchase now
gives you those updates and access to the final version.

Ray

On Tue, 06 Jun 2006 06:46:35 -0700, Ray B. wrote:

Yes, new versions are being released periodically. Your purchase now
gives you those updates and access to the final version.

If I understand correctly if I buy the paper version they will send it
to me as soon as it’s ready, but I’ve no access to the beta pdfs. Right?

Hi everyone,

Just for the sake of completeness & to let people know I got everying
working OK this morning.

In the end I completely un-installed xampp, downloaded InstantRails,
worked through to where I had the error ( rake db:migrate ) and all
worked well.

Hopefully now that this is working OK, things will be much smoother from
now on.

Thanks for everyone’s help.

regards, Dave P.

p.s. I don’t think the problem was necessarily with xampp, just an issue
with my WindowsXP/Apache/Mysql, etc… setup.

At 04:16 AM 6/6/2006, you wrote:


I checked out that section and it tells you to type:
mysql -u root depot_developement to test to see if you can connect and I
get an error:
Error 1045 Access denied for user root@localhost using password NO

i am db challenged. on linux, i do a:

bin/mysqld_safe --user=mysql &

bin/mysqladmin -u root password ‘new-password’
bin/mysqladmin -u root -h hostname password ‘new-password’

using ‘’’ (two single quotes) to get an empy root login. not sure how
i did it on windoze.

But phpMyAdmin works fine with the root login, so I’m a little confused
as to why that is happening ?

i have no clue. but i am an old guy with nanosecond short term
memory, so i wrote a script that runs under cygwin on my windoze box
(see below). everything seems to work in the iteration A’s except for
the style sheet.

thanks

initialize() {
rm -rf $name
initializedb
}
initializedb() {
mysqladmin -f -u root drop ${name}_development
mysqladmin -u root create ${name}_development
mysqladmin -f -u root drop ${name}_test
mysqladmin -u root create ${name}_test
mysqladmin -f -u root drop ${name}_production
mysqladmin -u root create ${name}_production
}
showtables() {
for i in $*
do
mysql -u root <<-!!eof
use ${name}_development;
show tables;
describe $i;
!!eof
done
}
iterationA1() {
echo rake db:migrate
rake.bat db:migrate
echo script/generate model Product
ruby script/generate model Product
echo “edit migration file”
#read x
cat > db/migrate/001_create_products.rb <<-!!eof
class CreateProducts < ActiveRecord::Migration
def self.up
create_table :products do |t|
t.column :title, :string
t.column :description, :text
t.column :image_url, :string
end
end
def self.down
drop_table :products
end
end
!!eof
echo rake db:migrate
rake.bat db:migrate
showtables products
echo ruby script/generate controller admin
ruby script/generate controller admin
echo edit controller
cat > app/controllers/admin_controller.rb <<-!!eof
class AdminController < ApplicationController
scaffold :product
end
!!eof
}
iterationA2() {
ruby script/generate migration add_price
cat > db/migrate/002_add_price.rb <<-!!eof
class AddPrice < ActiveRecord::Migration
def self.up
add_column :products, :price, :integer, :default =>
0
end
def self.down
remove_column :products, :price
end
end
!!eof
rake.bat db:migrate
showtables products
}
iterationA3() {
cat > app/models/product.rb <<-!!eof
class Product < ActiveRecord::Base
validates_presence_of :title, :description,
:image_url
validates_numericality_of :price, :only_integer =>
true
validates_uniqueness_of :title
validates_format_of :image_url,
:with => %r{.(gif|jpg|png)$}i,
:message => “must be a URL for a GIF, JPG, or PNG
image”
protected
def validate
errors.add(:price, “should be positive”) if
price.nil? || price <= 0
end
end
!!eof
}
iterationA4() {
ruby script/generate scaffold product admin
ruby script/generate migration add_test_data
cat > db/migrate/003_add_test_data.rb <<-!!eof
class AddTestData < ActiveRecord::Migration
def self.up

                 Product.create(:title => 'Pragmatic Project 

Automation’,
:description =>
%{


Pragmatic Project Automation shows
you how to improve the
consistency and repeatability of your
project’s procedures using
automation to reduce risk and errors.



Simply put, we’re going to put this thing
called a computer to work
for you doing the mundane (but important)
project stuff. That means
you’ll have more time and energy to do the
really
exciting—and difficult—stuff, like
writing quality code.

},
:image_url => ‘/images/auto.jpg’,
:price => 2995)

                 Product.create(:title => 'Pragmatic Version 

Control’,
:description =>
%{


This book is a recipe-based approach to
using Subversion that will
get you up and running quickly—and
correctly. All projects need
version control: it’s a foundational piece
of any project’s
infrastructure. Yet half of all project
teams in the U.S. don’t use
any version control at all. Many others
don’t use it well, and end
up experiencing time-consuming problems.

},
:image_url => ‘/images/svn.jpg’,
:price => 2850)

                 # . . .


                 Product.create(:title => 'Pragmatic Unit Testing 

(C#)',
:description =>
%{


Pragmatic programmers use feedback to drive
their development and
personal processes. The most valuable
feedback you can get while
coding comes from unit testing.



Without good tests in place, coding can
become a frustrating game of
“whack-a-mole.” That’s the carnival game
where the player strikes at a
mechanical mole; it retreats and another
mole pops up on the opposite side
of the field. The moles pop up and down so
fast that you end up flailing
your mallet helplessly as the moles continue
to pop up where you least
expect them.

},
:image_url => ‘/images/utc.jpg’,
:price => 2775)

               end

               def self.down
                 Product.delete_all
               end
             end
             !!eof
     rake.bat db:migrate
     mysql -u root <<-!!eof
             use ${name}_development;
             show tables;
             describe products;
             select title,image_url from products;
     !!eof
     cat > app/views/layouts/admin.rhtml <<-!!eof
             <html>
               <head>
                 <title>Admin: <%= controller.action_name %></title>
                 <%= stylesheet_link_tag 'scaffold', 'depot' %>
               </head>
               <body>
                 <p style="color: green"><%= flash[:notice] %></p>
                 <%= @content_for_layout %>
               </body>
             </html>
             !!eof
     cp ../images/* public/images/
     cp ../depot.css public/stylesheets/

}
set -x
base=i:/work
PATH=/cygdrive/$base:$PATH
name=depot
cd $base
initialize
echo rails
rails.cmd $name
cd $name
echo iterationA1
iterationA1
Ruby script/server
echo iterationA2
iterationA2
iterationA3
iterationA4
ruby script/server


vice-chair http://ocjug.org/

I purchased the pdf yesterday. It was confusing though becasue it
states
that if your purchase both pdf and book the pdf would be sent at the
time of
the actual release. I’d think though if you got the pdf you could
download
the beta now and receive updates regularly but perhaps that is not the
case.

Stuart