Rails to English

I am currently using the book “Agile Web D. With
Rails” (2005). I am working on a fully function web application that
has a shopping cart.

The web page displays this,

ActiveRecord::StatementInvalid in AdminController#create

Mysql::Error: #23000Column ‘date_available’ cannot be null: INSERT
INTO products (image_url, date_available, price, title,
description) VALUES(‘http://www.google.com/pic.jpg’, NULL, ‘9.99’,
‘asdf’, ‘asdf’)

RAILS_ROOT: ./script/…/config/…
Application Trace | Framework Trace | Full Trace

c:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/
connection_adapters/abstract_adapter.rb:128:in log' c:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/ connection_adapters/mysql_adapter.rb:243:in execute’
c:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/
connection_adapters/mysql_adapter.rb:253:in insert' c:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/ base.rb:1811:in create_without_callbacks’
c:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/
callbacks.rb:254:in create_without_timestamps' c:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/ timestamp.rb:39:in create’
c:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/
base.rb:1789:in create_or_update_without_callbacks' c:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/ callbacks.rb:242:in create_or_update’
c:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/
base.rb:1545:in save_without_validation' c:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/ validations.rb:752:in save_without_transactions’
c:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/
transactions.rb:129:in save' c:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/ connection_adapters/abstract/database_statements.rb:59:in transaction’
c:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/
transactions.rb:95:in transaction' c:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/ transactions.rb:121:in transaction’
c:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/
transactions.rb:129:in save' #{RAILS_ROOT}/app/controllers/admin_controller.rb:25:in create’

c:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/
connection_adapters/abstract_adapter.rb:128:in log' c:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/ connection_adapters/mysql_adapter.rb:243:in execute’
c:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/
connection_adapters/mysql_adapter.rb:253:in insert' c:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/ base.rb:1811:in create_without_callbacks’
c:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/
callbacks.rb:254:in create_without_timestamps' c:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/ timestamp.rb:39:in create’
c:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/
base.rb:1789:in create_or_update_without_callbacks' c:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/ callbacks.rb:242:in create_or_update’
c:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/
base.rb:1545:in save_without_validation' c:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/ validations.rb:752:in save_without_transactions’
c:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/
transactions.rb:129:in save' c:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/ connection_adapters/abstract/database_statements.rb:59:in transaction’
c:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/
transactions.rb:95:in transaction' c:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/ transactions.rb:121:in transaction’
c:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/
transactions.rb:129:in save' c:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/ base.rb:1095:in send’
c:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/
base.rb:1095:in perform_action_without_filters' c:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/ filters.rb:632:in call_filter’
c:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/
filters.rb:638:in call_filter' c:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/ filters.rb:438:in call’
c:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/
filters.rb:637:in call_filter' c:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/ filters.rb:619:in perform_action_without_benchmark’
c:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/
benchmarking.rb:66:in perform_action_without_rescue' c:/ruby/lib/ruby/1.8/benchmark.rb:293:in measure’
c:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/
benchmarking.rb:66:in perform_action_without_rescue' c:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/ rescue.rb:83:in perform_action’
c:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/
base.rb:430:in send' c:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/ base.rb:430:in process_without_filters’
c:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/
filters.rb:624:in process_without_session_management_support' c:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/ session_management.rb:114:in process’
c:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/
base.rb:330:in process' c:/ruby/lib/ruby/gems/1.8/gems/rails-1.2.3/lib/dispatcher.rb:41:in dispatch’
c:/ruby/lib/ruby/gems/1.8/gems/rails-1.2.3/lib/webrick_server.rb:
113:in handle_dispatch' c:/ruby/lib/ruby/gems/1.8/gems/rails-1.2.3/lib/webrick_server.rb:79:in service’
c:/ruby/lib/ruby/1.8/webrick/httpserver.rb:104:in service' c:/ruby/lib/ruby/1.8/webrick/httpserver.rb:65:in run’
c:/ruby/lib/ruby/1.8/webrick/server.rb:173:in start_thread' c:/ruby/lib/ruby/1.8/webrick/server.rb:162:in start’
c:/ruby/lib/ruby/1.8/webrick/server.rb:162:in start_thread' c:/ruby/lib/ruby/1.8/webrick/server.rb:95:in start’
c:/ruby/lib/ruby/1.8/webrick/server.rb:92:in each' c:/ruby/lib/ruby/1.8/webrick/server.rb:92:in start’
c:/ruby/lib/ruby/1.8/webrick/server.rb:23:in start' c:/ruby/lib/ruby/1.8/webrick/server.rb:82:in start’
c:/ruby/lib/ruby/gems/1.8/gems/rails-1.2.3/lib/webrick_server.rb:63:in
dispatch' c:/ruby/lib/ruby/gems/1.8/gems/rails-1.2.3/lib/commands/servers/ webrick.rb:59 c:/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in gem_original_require’
c:/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in
require' c:/ruby/lib/ruby/gems/1.8/gems/activesupport-1.4.2/lib/active_support/ dependencies.rb:495:in require’
c:/ruby/lib/ruby/gems/1.8/gems/activesupport-1.4.2/lib/active_support/
dependencies.rb:342:in new_constants_in' c:/ruby/lib/ruby/gems/1.8/gems/activesupport-1.4.2/lib/active_support/ dependencies.rb:495:in require’
c:/ruby/lib/ruby/gems/1.8/gems/rails-1.2.3/lib/commands/server.rb:39
c:/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in
gem_original_require' c:/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in require’
script/server:3

c:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/
connection_adapters/abstract_adapter.rb:128:in log' c:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/ connection_adapters/mysql_adapter.rb:243:in execute’
c:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/
connection_adapters/mysql_adapter.rb:253:in insert' c:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/ base.rb:1811:in create_without_callbacks’
c:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/
callbacks.rb:254:in create_without_timestamps' c:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/ timestamp.rb:39:in create’
c:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/
base.rb:1789:in create_or_update_without_callbacks' c:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/ callbacks.rb:242:in create_or_update’
c:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/
base.rb:1545:in save_without_validation' c:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/ validations.rb:752:in save_without_transactions’
c:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/
transactions.rb:129:in save' c:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/ connection_adapters/abstract/database_statements.rb:59:in transaction’
c:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/
transactions.rb:95:in transaction' c:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/ transactions.rb:121:in transaction’
c:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/
transactions.rb:129:in save' #{RAILS_ROOT}/app/controllers/admin_controller.rb:25:in create’
c:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/
base.rb:1095:in send' c:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/ base.rb:1095:in perform_action_without_filters’
c:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/
filters.rb:632:in call_filter' c:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/ filters.rb:638:in call_filter’
c:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/
filters.rb:438:in call' c:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/ filters.rb:637:in call_filter’
c:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/
filters.rb:619:in perform_action_without_benchmark' c:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/ benchmarking.rb:66:in perform_action_without_rescue’
c:/ruby/lib/ruby/1.8/benchmark.rb:293:in measure' c:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/ benchmarking.rb:66:in perform_action_without_rescue’
c:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/
rescue.rb:83:in perform_action' c:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/ base.rb:430:in send’
c:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/
base.rb:430:in process_without_filters' c:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/ filters.rb:624:in process_without_session_management_support’
c:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/
session_management.rb:114:in process' c:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/ base.rb:330:in process’
c:/ruby/lib/ruby/gems/1.8/gems/rails-1.2.3/lib/dispatcher.rb:41:in
dispatch' c:/ruby/lib/ruby/gems/1.8/gems/rails-1.2.3/lib/webrick_server.rb: 113:in handle_dispatch’
c:/ruby/lib/ruby/gems/1.8/gems/rails-1.2.3/lib/webrick_server.rb:79:in
service' c:/ruby/lib/ruby/1.8/webrick/httpserver.rb:104:in service’
c:/ruby/lib/ruby/1.8/webrick/httpserver.rb:65:in run' c:/ruby/lib/ruby/1.8/webrick/server.rb:173:in start_thread’
c:/ruby/lib/ruby/1.8/webrick/server.rb:162:in start' c:/ruby/lib/ruby/1.8/webrick/server.rb:162:in start_thread’
c:/ruby/lib/ruby/1.8/webrick/server.rb:95:in start' c:/ruby/lib/ruby/1.8/webrick/server.rb:92:in each’
c:/ruby/lib/ruby/1.8/webrick/server.rb:92:in start' c:/ruby/lib/ruby/1.8/webrick/server.rb:23:in start’
c:/ruby/lib/ruby/1.8/webrick/server.rb:82:in start' c:/ruby/lib/ruby/gems/1.8/gems/rails-1.2.3/lib/webrick_server.rb:63:in dispatch’
c:/ruby/lib/ruby/gems/1.8/gems/rails-1.2.3/lib/commands/servers/
webrick.rb:59
c:/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in
gem_original_require' c:/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in require’
c:/ruby/lib/ruby/gems/1.8/gems/activesupport-1.4.2/lib/active_support/
dependencies.rb:495:in require' c:/ruby/lib/ruby/gems/1.8/gems/activesupport-1.4.2/lib/active_support/ dependencies.rb:342:in new_constants_in’
c:/ruby/lib/ruby/gems/1.8/gems/activesupport-1.4.2/lib/active_support/
dependencies.rb:495:in require' c:/ruby/lib/ruby/gems/1.8/gems/rails-1.2.3/lib/commands/server.rb:39 c:/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in gem_original_require’
c:/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in
`require’
script/server:3

Request

Parameters: {“commit”=>“Create”, “product”=>{“image_url”=>“http://
www.google.com/pic.jpg”, “price”=>“9.99”, “title”=>“asdf”,
“description”=>“asdf”}}

Show session dump


flash: !map:ActionController::Flash::FlashHash {}

Response
Headers: {“cookie”=>[], “Cache-Control”=>“no-cache”}

Does anyone know what it is saying in english?

Does anyone know what it is saying in english?

It’s saying that “‘date_available’ cannot be null” - you must have a NOT
NULL constraint on the products table, and so if you want to
successfully insert a record into that table, you’ll need to provide a
value for date_available.

Wes

Mr. Watson wrote:

Mysql::Error: #23000Column ‘date_available’ cannot be null: INSERT
INTO products (image_url, date_available, price, title,
description) VALUES(‘http://www.google.com/pic.jpg’, NULL, ‘9.99’,
‘asdf’, ‘asdf’)

Does anyone know what it is saying in english?

Next time, don’t worry about copying in the entire backtrace!

Open mysql (with like mysql -u root), “use” your database, and run that
INSERT line.

Then run “show create table products;”. You probably have a “NOT NULL”
on
the “date_available” line.

Rails is a thin wrapper on several technologies (HTML, SQL, YAML,
etc.).
You need to start learning to work with each of them, because Rails will
only take you so far, then drop you.

Change the migration that creates your products table, remove the :null
=>
false, drop and recreate your database, and run rake db:migrate.


Phlip

How do I give “date_available” a value. The book does NOT give it a
value. The book says,

Go to mySQL and type this:

drop table if exists products;
create table products (
id int not null auto_increment,
title varchar(100) not null,
description text not null,
image_url varchar(200) not null,
price decimal(10,2) not null,
date_available datetime not null,
primary key (id)
);

And it shows a web page with the date and time in the book.

I am not sure how to approach this.

And it shows a web page with the date and time in the book.

Again, remove the “not null” from that creator:

price decimal(10,2) not null,
date_available datetime,
primary key (id)

Again: Look up a tutorial on SQL, such as MySQL, and just read it for a
while.


Phlip

When I type in the insert into products in MySQL it says,

"Error 1064 (42000); You have an error in your SQL syntax; check the
manual that corresponds to your MySQL server version for the right
syntax to use near ‘’ at line 2

Try setting prod.date_available to Time.now.

Ok.

Thank you. You are very helpful.

When I type in the insert into products in MySQL it says,

Next time copy-and-paste it. Don’t type it all in by hand!

"Error 1064 (42000); You have an error in your SQL syntax; check the
manual that corresponds to your MySQL server version for the right
syntax to use near ‘’ at line 2

That could be as trivial as a missing ; on the end. The excessive error
message is an attempt to reduce entry-level questions on the forums…


Phlip

On 10/6/07, Mr. Watson [email protected] wrote:

description text not null,
image_url varchar(200) not null,
price decimal(10,2) not null,
date_available datetime not null,
primary key (id)
);

And it shows a web page with the date and time in the book.

I am not sure how to approach this.

You said that you are using the 2005 edition of AWDWR. It looks like
you are quoting from p. 62. Did you follow the step of regenerating
your scaffold code which comes after this.

BUT. I notice from the walkback that you are using ActiveRecord
1.15.3 which is pretty new. The first edition of AWDWR is pretty
outdated, and thinks might not work exactly the same way with Rails
1.2.

You REALLY should consider getting the new edition. For one thing it
uses the (now not so) new migration function to manage db schema
evolution.


Rick DeNatale

My blog on Ruby
http://talklikeaduck.denhaven2.com/