Jul 10, 2008
Smallcat_small Bill Thayer 9 posts

Topic: Agile Web Development with Rails, 3rd Edition / Undoing a migration....

I even tried going back to VERSION=5 but got the same result:



C:\InstantRails-2.0-win\rails_apps\depot>rake db:migrate VERSION=5
(in C:/InstantRails-2.0-win/rails_apps/depot)
== 6 CreateLineItems: reverting ===============================================
-- drop_table(:line_items)
   -> 0.0470s
== 6 CreateLineItems: reverted (0.0470s) ======================================

C:\InstantRails-2.0-win\rails_apps\depot>rake db:migrate
(in C:/InstantRails-2.0-win/rails_apps/depot)
== 6 CreateLineItems: migrating ===============================================
-- create_table(:line_items)
   -> 0.0470s
== 6 CreateLineItems: migrated (0.0470s) ======================================

== 7 CreatePaymentTypes: migrating ============================================
-- create_table(:payment_types)
rake aborted!
Mysql::Error: Table 'payment_types' already exists: CREATE TABLE `payment_types` (`id` int(11) DEFAULT NULL auto_increment PRIMARY KEY, `label` varchar(255) DEF
AULT NULL, `value` varchar(255) DEFAULT NULL, `created_at` datetime DEFAULT NULL, `updated_at` datetime DEFAULT NULL) ENGINE=InnoDB

(See full trace by running task with --trace)

C:\InstantRails-2.0-win\rails_apps\depot>

 
Jul 10, 2008
Smallcat_small Bill Thayer 9 posts

Topic: Agile Web Development with Rails, 3rd Edition / Undoing a migration....

Here’s my cmd window output:


C:\InstantRails-2.0-win\rails_apps\depot>rake db:migrate VERSION=6
(in C:/InstantRails-2.0-win/rails_apps/depot)

C:\InstantRails-2.0-win\rails_apps\depot>rake db:migrate --trace
(in C:/InstantRails-2.0-win/rails_apps/depot)
** Invoke db:migrate (first_time)
** Invoke environment (first_time)
** Execute environment
** Execute db:migrate
== 7 CreatePaymentTypes: migrating ============================================
-- create_table(:payment_types)
rake aborted!
Mysql::Error: Table 'payment_types' already exists: CREATE TABLE `payment_types` (`id` int(11) DEFAULT NULL auto_increment PRIMARY KEY, `label` varchar(255) DEF
AULT NULL, `value` varchar(255) DEFAULT NULL, `created_at` datetime DEFAULT NULL, `updated_at` datetime DEFAULT NULL) ENGINE=InnoDB
C:/InstantRails-2.0-win/ruby/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/active_record/connection_adapters/abstract_adapter.rb:150:in `log'
C:/InstantRails-2.0-win/ruby/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/active_record/connection_adapters/mysql_adapter.rb:281:in `execute'
C:/InstantRails-2.0-win/ruby/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/active_record/connection_adapters/abstract/schema_statements.rb:104:in `create_table'

C:/InstantRails-2.0-win/ruby/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/active_record/connection_adapters/mysql_adapter.rb:416:in `create_table'
C:/InstantRails-2.0-win/ruby/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/active_record/migration.rb:285:in `send'
C:/InstantRails-2.0-win/ruby/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/active_record/migration.rb:285:in `method_missing'
C:/InstantRails-2.0-win/ruby/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/active_record/migration.rb:265:in `say_with_time'
C:/InstantRails-2.0-win/ruby/lib/ruby/1.8/benchmark.rb:293:in `measure'
C:/InstantRails-2.0-win/ruby/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/active_record/migration.rb:265:in `say_with_time'
C:/InstantRails-2.0-win/ruby/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/active_record/migration.rb:281:in `method_missing'
./db/migrate//007_create_payment_types.rb:3:in `up_without_benchmarks'
C:/InstantRails-2.0-win/ruby/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/active_record/migration.rb:219:in `send'
C:/InstantRails-2.0-win/ruby/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/active_record/migration.rb:219:in `migrate'
C:/InstantRails-2.0-win/ruby/lib/ruby/1.8/benchmark.rb:293:in `measure'
C:/InstantRails-2.0-win/ruby/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/active_record/migration.rb:219:in `migrate'
C:/InstantRails-2.0-win/ruby/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/active_record/migration.rb:348:in `migrate'
C:/InstantRails-2.0-win/ruby/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/active_record/migration.rb:339:in `each'
C:/InstantRails-2.0-win/ruby/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/active_record/migration.rb:339:in `migrate'
C:/InstantRails-2.0-win/ruby/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/active_record/migration.rb:307:in `up'
C:/InstantRails-2.0-win/ruby/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/active_record/migration.rb:298:in `migrate'
C:/InstantRails-2.0-win/ruby/lib/ruby/gems/1.8/gems/rails-2.0.2/lib/tasks/databases.rake:85
C:/InstantRails-2.0-win/ruby/lib/ruby/gems/1.8/gems/rake-0.8.1/lib/rake.rb:546:in `call'
C:/InstantRails-2.0-win/ruby/lib/ruby/gems/1.8/gems/rake-0.8.1/lib/rake.rb:546:in `execute'
C:/InstantRails-2.0-win/ruby/lib/ruby/gems/1.8/gems/rake-0.8.1/lib/rake.rb:541:in `each'
C:/InstantRails-2.0-win/ruby/lib/ruby/gems/1.8/gems/rake-0.8.1/lib/rake.rb:541:in `execute'
C:/InstantRails-2.0-win/ruby/lib/ruby/gems/1.8/gems/rake-0.8.1/lib/rake.rb:508:in `invoke_with_call_chain'
C:/InstantRails-2.0-win/ruby/lib/ruby/gems/1.8/gems/rake-0.8.1/lib/rake.rb:501:in `synchronize'
C:/InstantRails-2.0-win/ruby/lib/ruby/gems/1.8/gems/rake-0.8.1/lib/rake.rb:501:in `invoke_with_call_chain'
C:/InstantRails-2.0-win/ruby/lib/ruby/gems/1.8/gems/rake-0.8.1/lib/rake.rb:494:in `invoke'
C:/InstantRails-2.0-win/ruby/lib/ruby/gems/1.8/gems/rake-0.8.1/lib/rake.rb:1931:in `invoke_task'
C:/InstantRails-2.0-win/ruby/lib/ruby/gems/1.8/gems/rake-0.8.1/lib/rake.rb:1909:in `top_level'
C:/InstantRails-2.0-win/ruby/lib/ruby/gems/1.8/gems/rake-0.8.1/lib/rake.rb:1909:in `each'
C:/InstantRails-2.0-win/ruby/lib/ruby/gems/1.8/gems/rake-0.8.1/lib/rake.rb:1909:in `top_level'
C:/InstantRails-2.0-win/ruby/lib/ruby/gems/1.8/gems/rake-0.8.1/lib/rake.rb:1948:in `standard_exception_handling'
C:/InstantRails-2.0-win/ruby/lib/ruby/gems/1.8/gems/rake-0.8.1/lib/rake.rb:1903:in `top_level'
C:/InstantRails-2.0-win/ruby/lib/ruby/gems/1.8/gems/rake-0.8.1/lib/rake.rb:1881:in `run'
C:/InstantRails-2.0-win/ruby/lib/ruby/gems/1.8/gems/rake-0.8.1/lib/rake.rb:1948:in `standard_exception_handling'
C:/InstantRails-2.0-win/ruby/lib/ruby/gems/1.8/gems/rake-0.8.1/lib/rake.rb:1878:in `run'
C:/InstantRails-2.0-win/ruby/lib/ruby/gems/1.8/gems/rake-0.8.1/bin/rake:31
C:/InstantRails-2.0-win/ruby/bin/rake:19:in `load'
C:/InstantRails-2.0-win/ruby/bin/rake:19

C:\InstantRails-2.0-win\rails_apps\depot>

 
Jul 10, 2008
Smallcat_small Bill Thayer 9 posts

Topic: Agile Web Development with Rails, 3rd Edition / Undoing a migration....

Thank you James & Steve.

My bad. After going through my command history I see I had the syntax wrong. I typed:

depot>rake db:migrate version = 6

it should have been

depot>rake db:migrate VERSION=6

I guess the caps and no spaces matter for the argument VERSION=6.

My next post will be the output from my console after running >rake db:migrate—trace

Here is my 007_create_payment_types.rb file:


class CreatePaymentTypes < ActiveRecord::Migration
  def self.up
    create_table :payment_types do |t|
      t.string :label
      t.string :value

      t.timestamps
    end
  end

  def self.down
    drop_table :payment_types
  end
end

 
Jul 9, 2008
Smallcat_small Bill Thayer 9 posts

Topic: Agile Web Development with Rails, 3rd Edition / Undoing a migration....

While attempting to move the payment options to a database table I get migration errors. I’ve been trying to revert back using >rake db:migrate VERSION=6 but I get the same errors. Basically it says that the table ‘payment_types’ exists but I’m under the impression that >rake db:migrate VERSION=6 should remove that table.

This is a partial copy from my cmd window of my last attempt.
----------------------

C:\InstantRails-2.0-win\rails_apps\depot>ruby script/generate scaffold payment_type label:string value:string

exists  app/models/
exists  app/controllers/
exists  app/helpers/
exists  app/views/payment_types
exists  app/views/layouts/
exists  test/functional/
exists  test/unit/
identical  app/views/payment_types/index.html.erb
identical  app/views/payment_types/show.html.erb
identical  app/views/payment_types/new.html.erb
identical  app/views/payment_types/edit.html.erb
identical  app/views/layouts/payment_types.html.erb
identical  public/stylesheets/scaffold.css
dependency  model
exists    app/models/
exists    test/unit/
exists    test/fixtures/
skip    app/models/payment_type.rb
identical    test/unit/payment_type_test.rb
skip    test/fixtures/payment_types.yml
exists    db/migrate
create    db/migrate/007_create_payment_types.rb
identical  app/controllers/payment_types_controller.rb
identical  test/functional/payment_types_controller_test.rb
identical  app/helpers/payment_types_helper.rb
route  map.resources :payment_types

C:\InstantRails-2.0-win\rails_apps\depot>rake db:migrate
(in C:/InstantRails-2.0-win/rails_apps/depot)
7 CreatePaymentTypes: migrating ==========================================
—create_table(:payment_types)
rake aborted!
Mysql::Error: Table ‘payment_types’ already exists: CREATE TABLE `payment_types` (`id` int(11) DEFAULT NULL auto_increment PRIMARY KEY, `label` varchar(255) DEF
AULT NULL, `value` varchar(255) DEFAULT NULL, `created_at` datetime DEFAULT NULL, `updated_at` datetime DEFAULT NULL) ENGINE=InnoDB

(See full trace by running task with—trace)

 
Jul 9, 2008
Smallcat_small Bill Thayer 9 posts

Topic: Agile Web Development with Rails, 3rd Edition / RJS Error --- Starting over.

Thank you dave. I downloaded the code one file at a time until it worked again. I did not do a diff because I’m more of an overwrite-the-old-file kind of guy. I do wish I knew how to debug stuff like that because I still have no idea what went wrong.

 
Jul 7, 2008
Smallcat_small Bill Thayer 9 posts

Topic: Agile Web Development with Rails, 3rd Edition / RJS Error --- Starting over.

Ok,

I’m to the point now that all I can do is delete my depot app and start over. I can’t believe that I’m the only one who had trouble at this point.

Regards,
Bill

 
Jul 7, 2008
Smallcat_small Bill Thayer 9 posts

Topic: Agile Web Development with Rails, 3rd Edition / RJS error: TypeError: null value....

Thank you Ben,

I tried your solution by changing the class= to id= in _cart.html.erb. I really didn’t see any other file where it would makes sense to try it. The result is that the cart title was not bold. The product id does get passed to the add_to_cart function so otherwise the app is fine. It does update the cart correctly by adding the item but does not render without hitting an F5 (refresh). The “Empty Cart” button works as expected and does not throw the RJS error.

Regards,
Bill

 
Jun 24, 2008
Smallcat_small Bill Thayer 9 posts

Topic: Agile Web Development with Rails, 3rd Edition / RJS error: TypeError: null value....

...or TypeError: object has no properties for FireFox, and a [object Error} in IE when using “respond_to { |format| format.js }”

Hello,

So far great book but this error has stopped me and I cannot move forward (I tried). I have read all of the posts here, double checked my code, checked all of the troubleshooting tips on page 132, experimented a little and still cannot get a clue as to what’s wrong. Please help because I must get past this.

Symptoms:
I click on an Add to Cart Item and get an RJS error dialog box followed by another dialog box with the portion of the code below within the try block.

try {
Element.update(“cart”, ”\n\u003Ch1\u003EYour Pragmatic Cart\u003C/h1\u003E\n\u003Cdiv class=\”cart-title\”\u003EYour Cart\u003C/div\u003E\n\u003Ctable\u003E\n\t\n\t\u003Ctr\u003E\n\n\t\u003Ctd\u003E1\u0026times;\u003C/td\u003E\n\t\u003Ctd\u003EPragmatic Project Automation\u003C/td\u003E\n\t\u003Ctd class=\”item-price\”\u003E$29.95\u003C/td\u003E\n\u003C/tr\u003E\n\n\t\u003Ctr id=\”current_item\”\u003E\n\n\t\u003Ctd\u003E1\u0026times;\u003C/td\u003E\n\t\u003Ctd\u003EMy Cat Picture\u003C/td\u003E\n\t\u003Ctd class=\”item-price\”\u003E$0.01\u003C/td\u003E\n\u003C/tr\u003E\n\n\t\u003Ctr class=\”total-line\”\u003E\n\t\t\u003Ctd colspan=\”2\”\u003ETotal\u003C/td\u003E\n\t\t\u003Ctd class=\”total-cell\”\u003E$29.96\n\t\u003C/tr\u003E\n\u003C/table\u003E\n\n\n\n\u003Cform method=\”post\” action=\”/store/empty_cart\” class=\”button-to\”\u003E\u003Cdiv\u003E\u003Cinput type=\”submit\” value=\”Empty Cart\” /\u003E\u003Cinput name=\”authenticity_token\” type=\”hidden\” value=\”c32e382c02901e70877453742461b3f550effce9\” /\u003E\u003C/div\u003E\u003C/form\u003E\n”);
$(“current_item”).visualEffect(“highlight”, {“endcolor”: ”#114411”, “startcolor”: ”#88ff88”});
} catch (e) { alert(‘RJS error:\n\n’ + e.toString()); alert(‘Element.update(\”cart\”, \”\\n\\u003Ch1\\u003EYour Pragmatic Cart\\u003C/h1\\u003E\\n\\u003Cdiv class=\\\”cart-title\\\”\\u003EYour Cart\\u003C/div\\u003E\\n\\u003Ctable\\u003E\\n\\t\\n\\t\\u003Ctr\\u003E\\n\\n\\t\\u003Ctd\\u003E1\\u0026times;\\u003C/td\\u003E\\n\\t\\u003Ctd\\u003EPragmatic Project Automation\\u003C/td\\u003E\\n\\t\\u003Ctd class=\\\”item-price\\\”\\u003E$29.95\\u003C/td\\u003E\\n\\u003C/tr\\u003E\\n\\n\\t\\u003Ctr id=\\\”current_item\\\”\\u003E\\n\\n\\t\\u003Ctd\\u003E1\\u0026times;\\u003C/td\\u003E\\n\\t\\u003Ctd\\u003EMy Cat Picture\\u003C/td\\u003E\\n\\t\\u003Ctd class=\\\”item-price\\\”\\u003E$0.01\\u003C/td\\u003E\\n\\u003C/tr\\u003E\\n\\n\\t\\u003Ctr class=\\\”total-line\\\”\\u003E\\n\\t\\t\\u003Ctd colspan=\\\”2\\\”\\u003ETotal\\u003C/td\\u003E\\n\\t\\t\\u003Ctd class=\\\”total-cell\\\”\\u003E$29.96\\n\\t\\u003C/tr\\u003E\\n\\u003C/table\\u003E\\n\\n\\n\\n\\u003Cform method=\\\”post\\\” action=\\\”/store/empty_cart\\\” class=\\\”button-to\\\”\\u003E\\u003Cdiv\\u003E\\u003Cinput type=\\\”submit\\\” value=\\\”Empty Cart\\\” /\\u003E\\u003Cinput name=\\\”authenticity_token\\\” type=\\\”hidden\\\” value=\\\”c32e382c02901e70877453742461b3f550effce9\\\” /\\u003E\\u003C/div\\u003E\\u003C/form\\u003E\\n\”);\n$(\”current_item\”).visualEffect(\”highlight\”, {\”endcolor\”: \”#114411\”, \”startcolor\”: \”#88ff88\”});’); throw e }

I was able to get this try block above by clicking on the images. It returns a page and not a dialog box.

If I comment out the “respond_to { |format| format.js }” line in the add_to_cart method (see store_controller.rb) then use “redirect_to_index” in it’s place, clicking the image returns to me expected functionality on the page with the following output added to the development.log file:

Processing StoreController#add_to_cart (for 127.0.0.1 at 2008-06-24 14:50:13) [GET] Session ID: 8cff562dcdfcd4fb9787f48188e1afb4 Parameters: {“action”=>”add_to_cart”, “id”=>”1”, “controller”=>”store”} Product Columns (0.015000) SHOW FIELDS FROM `products` Product Load (0.000000) SELECT * FROM `products` WHERE (`products`.`id` = 1) 
Redirected to http://localhost:3000/store
Completed in 0.01500 (66 reqs/sec) | DB: 0.01500 (100%) | 302 Found [http://localhost/store/add_to_cart/1]

Processing StoreController#index (for 127.0.0.1 at 2008-06-24 14:50:14) [GET] Session ID: 8cff562dcdfcd4fb9787f48188e1afb4 Parameters: {“action”=>”index”, “controller”=>”store”} Product Load (0.000000) SELECT * FROM `products` ORDER BY title
Rendering template within layouts/store
Rendering store/index Product Columns (0.000000) SHOW FIELDS FROM `products`
Rendered store/_cart_item (0.00000)
Rendered store/_cart_item (0.00000)
Rendered store/_cart (0.00000)
Completed in 0.01500 (66 reqs/sec) | Rendering: 0.01500 (100%) | DB: 0.00000 (0%) | 200 OK [http://localhost/store]

Clicking on the “Add to Cart” button produces the same output in the log but the completion times vary. The cart does not update however until I hit F5.

Note:
No error messages are displayed unless I use the “respond_to { |format| format.js }” line.
The cart updates if I hit F5.

The output from the log file reads:

Processing StoreController#add_to_cart (for 127.0.0.1 at 2008-06-24 15:06:26) [POST] Session ID: 8cff562dcdfcd4fb9787f48188e1afb4 Parameters: {“commit”=>”Add to Cart”, “authenticity_token”=>”c32e382c02901e70877453742461b3f550effce9”, “action”=>”add_to_cart”, “id”=>”3”, “controller”=>”store”} Product Columns (0.000000) SHOW FIELDS FROM `products` Product Load (0.016000) SELECT * FROM `products` WHERE (`products`.`id` = 3) 
Rendering store/add_to_cart
Rendered store/_cart_item (0.00000)
Rendered store/_cart_item (0.00000)
Rendered store/_cart_item (0.00000)
Rendered store/_cart (0.00000)
Completed in 0.01600 (62 reqs/sec) | Rendering: 0.00000 (0%) | DB: 0.01600 (100%) | 200 OK [http://localhost/store/add_to_cart/3]

Thank you in advance for helping me.

Regards,
Bill


  def add_to_cart
      begin
    product = Product.find(params[:id])
      rescue ActiveRecord::RecordNotFound
          logger.error("Attempt to access invalid product #{params[:id]}")
    redirect_to_index("Invalid Product")
      else
    @cart = find_cart
    @current_item = @cart.add_product(product)
    respond_to { |format| format.js }
    #redirect_to_index
      end
    end




  def add_product(product)
      current_item = @items.find {|item| item.product == product}
      if current_item
      current_item.increment_quantity
      else
      current_item = CartItem.new(product)
      @items << current_item
      end
      current_item
  end
 
Jun 24, 2008
Smallcat_small Bill Thayer 9 posts

Topic: Agile Web Development with Rails, 3rd Edition / Text Editors for Rails (p38)

Netbeans 6.1 might be OK for experienced programmers but this newbie found it slow and confusing and slow.

Can’t go wrong with JEdit however I did have to edit the modes\catalog.xml file to add html.erb to the rhtml glob and add rjs to the ruby glob.

9 posts