small medium large xlarge

Generic-user-small
29 May 2006, 19:20
Fora User (865 posts)

This is the place to discuss the Depot Application: problems you may be having getting it running, questions about the description, and comments on just how bad Dave’s HTML and CSS skills are.

Generic-user-small
30 May 2006, 20:40
Fora User (865 posts)

Hi there. So far so good, but just ran into a little trouble. Starting from page 72 of the PDF:

I followed the instructions to add the price column using “ruby script/generate migration add_price”. I got the correct feedback from terminal. Next, I opened the page 002_add_price.rb in textmate, and added the code listed on page 73:

class AddPrice < ActiveRecord::Migration
def self.up
add_column :products, :price, :integer, :default => 0
end
def self.down
remove_column :products, :price
end
end

It seemed odd to have the “remove_column” line there, but that’s what page 73 shows. Next, I ran db:migrate. My terminal output didn’t match what’s shown on page 73. Mine looked like so:

mymac:~/work/depot mymac$ rake db:migrate
(in /Users/mylogin/work/depot)
== AddPrice: migrating ========================================================
== AddPrice: migrated (0.0000s) ===============================================

This line was missing in the output:
– add_column(:products, :price, :integer, {:default=>0})

I checked my database, and sure enough the price column wasn’t there. As a test, I deleted the “remove_column” line from 002_add_price.rb and tried rake again. No change. No price column.

I’m sure this is something really basic. Thanks for your patience.

Generic-user-small
07 Jun 2006, 07:37
Fora User (865 posts)

First, let me say that my comment is based on the 1st edition – I haven’t got the 2nd edition yet. My question is on how Dave uses render_component to display the cart contents from the display_cart action. It seems like an easier approach would be to render a partial. The same partial would be referenced from both the display_cart.rhmtl and the checkout.rhtml. Of course, you would have to manually add the Continue Shopping link, but it seems to be a more natural way of doing it than the work you have to do to customize the component for display.

Opinions?

Generic-user-small
26 May 2006, 01:28
Fora User (865 posts)

Well, after some goofing around, here are the steps I took to get things back on track with the tutorial:

  1. delete the file: add_price.rb
  2. change the file: schema.rb version from 2 to 1
  3. change the schema_info (in the actual database) from 2 to 1
  4. run: ruby script/generate migration add_price
  5. edit ONLY the up() method in the new file: add_price.rb.
  6. run: rake db:migrate
    Now the terminal output matches the depot tutorial, and “Price” magically appears on the admin page.

There may be an easier way to backtrack, but I’m new at this, and am just posting here for the benefit of other newbies who may run into the same problem. I’m not sure what the deal is with the down() method. Is that a mistake in the text?

Generic-user-small
26 May 2006, 02:42
Fora User (865 posts)

on page 81 (93 of PDF) the URL http://media.pragprog.com/titles/rails2/code/depot_c/public/images/ throws a 403 error.

Generic-user-small
27 May 2006, 01:00
Fora User (865 posts)

Boomer,

The down() method undoes what was done in the up method – allowing you to ‘rollback’, if you will, schema changes made by a migration. It allows you to move your database schema back to a prior state. I am not sure why you had the problem – I am fairly new to rails myself – but there is a lot of power in the migrations. -Bill Siggelkow

Generic-user-small
29 May 2006, 18:59
Fora User (865 posts)

You’re right – which is why the 2nd Edition does exactly that.

Components are deprecated, and as Stefan Kaes of RailsExpress put it: “I have yet to see any situation where I had to use a component instead of partials.”

Generic-user-small
29 May 2006, 19:20
Fora User (865 posts)

Man, do I love the revamp. Thumbs up!

Generic-user-small
29 May 2006, 20:27
Fora User (865 posts)

In the 1st edition, you used before_destroy() instead of safe_delete() to prevent the deletion of the last admin. Seems to me that before_destroy() was the better option.

After all, what if at some point in time a second developer came sneaking around the corner? He might overlook using safe_delete() and before we knew it we’d get a support call, responding: “but that shouldn’t be possible…”

Using before_destroy() could prevent such foot-shooting.

Generic-user-small
30 May 2006, 20:40
Fora User (865 posts)

The self.up runs when you migrate up to a new version of the database schema. The self.down only runs if you decide to reverse that change and migrate back down to a previous version.

The problem is that when you are writing self.down you are writing code that you will forget to test. But you will try to run it when you are in some sort of duress. Why else would you reverse the change to a database? Okay, possibly you just changed your mind, but possibly because you installed a change that broke things in a very visible way. And maybe people are complaining. At that point you will probably run the .down methods for the very first time in history.

So maybe test the self.down method when you migrate up, as well?

Generic-user-small
02 Jun 2006, 17:05
Fora User (865 posts)

Why does the product listing in the ‘store’ view not place the products ordered by their ‘id’ and the ‘admin list’ view does?

Generic-user-small
02 Jun 2006, 17:05
Fora User (865 posts)

OK so after some rarely used brain cells came out of hiding I looked on page 101 where the product.rb was setup to sort the products by ‘title’ and switched it to ‘id’ to have the store load the products in order…

Generic-user-small
04 Jun 2006, 16:06
Fora User (865 posts)

imagine a cart in a sidebar which require instance variable @cart to be initialized before rendering. I want to avoid to forget setting up an before_filter in my controller and keep things simple.

why exactly are components deprecated? I don’t even find a hint on the RoR about deprecation?

Generic-user-small
07 Jun 2006, 08:39
Fora User (865 posts)

Hi all,

Just working thru the depot app and when I type:

ruby script/generate model Product

I wondered why is it ‘ruby’ and not ‘rails’

cheers, Dave Porter

Generic-user-small
07 Jun 2006, 07:37
Fora User (865 posts)

You might find these three links interesting:

  • “The case against high-level components”:http://www.loudthinking.com/arc/000407.html
  • “Components may not be evil, but they sure are distracting”:http://weblog.rubyonrails.org/articles/2005/11/11/why-engines-and-components-are-not-evil-but-distracting
  • “Components may not be evil, but they sure can be slow”:http://railsexpress.de/blog/articles/2005/11/18/components-may-not-be-evil-but-they-sure-can-be-slow
Generic-user-small
07 Jun 2006, 07:39
Fora User (865 posts)

If you look in the script/generate file, you’ll notice that it contains Ruby code. And it needs the Ruby interpreter to run that code.

Remember that Rails is a language on top of Ruby. So any Rails script or application gets run by the Ruby interpreter, which first loads the Rails framework to extend the Ruby language.

Hope that makes any sense to you.

Generic-user-small
07 Jun 2006, 08:39
Fora User (865 posts)

Thanks Roderick - appreciate that ! Dave

Generic-user-small
07 Jun 2006, 23:00
Fora User (865 posts)

Hi All,

I have downloaded the code for the book (to spare my fingers), but I’m finding it difficult to correlate the different versions with the 2nd edition of the book ?

e.g. I’m up to Iteration B2 ( 7.2 ) on page 91, but how do I know where the code is at ?

cheers, Dave Porter

Generic-user-small
07 Jun 2006, 09:03
Fora User (865 posts)

Hi All,

When I get to this view in my browser, the price and the line that breaks each product are the wrong way round !

I cannot see where is the code that places the line between the products listed ?

TIA, Dave Porter

Generic-user-small
07 Jun 2006, 18:47
Fora User (865 posts)

Me again procastinating other work :)

If you look at the snippets of source code throughout the text, you’ll notice a download link. That link also has the version corresponding to the depot application.

Generic-user-small
07 Jun 2006, 23:00
Fora User (865 posts)

Ah, yes, the reason I didn;t notice that was that the text size of those snippets is too small for me to read normally, but I’ll keep my magnifying glass handy from now on !

cheers, Dave

Generic-user-small
08 Jun 2006, 03:46
Fora User (865 posts)

On page 72, you say, “Our convention is to use the verb create when a migration creates tables, and add when it adds columns to an existing table.”

But, on page 82, you create a data-only migration called, add_test_data.rb

I assert that I think a cleaner naming convention would be to name this migration insert_test_data.rb instead. I realize migrations are new (and weren’t in the first edition), but I think this makes for cleaner separation of function.

Generic-user-small
07 Sep 2006, 15:24
Fora User (865 posts)

Hi All,

I’m up to D3 on page 128 ( section 9.3 ) and this just does not work for me. I copied over the depot_m & depot_n code ( hope there are no errors in them !), but can’t get the highlight changes effect.

I tried in IE, Firefox and Opera in case it was a browser issue, but I also noticed that the shopping cart does not refresh. But when I F5 to refresh it updates with the correct info. Maybe a bug somewhere ?

cheers, Dave Porter

Generic-user-small
23 Jun 2006, 19:52
Fora User (865 posts)

Ok, so I’ve been successfully plowing through the “depot” application up until this point. Instead of my app looking like it should, when it displays the prices, they are instead placed just underneath the next <div> bar. I can’t quite place why it is happening. I’ve even gone so far as to download the store.rhtml, index.rhtml, and depot.css files to make sure it wasn’t a typo. Also, I figured out that if I remove the text ‘class=”price”’ from the tag on line 8 of index.rhtml, it places the price just fine, but of course with no font/coloration. Any help is appreciated.

neogia

Generic-user-small
09 Jun 2006, 18:27
Fora User (865 posts)

1111111111111111

Generic-user-small
10 Jun 2006, 01:41
Fora User (865 posts)

So… is this a messed up post, or was that meant to be informational :)

Generic-user-small
20 Jun 2006, 10:57
Fora User (865 posts)

Hi,

I tried to make the Depot application and it didn’t work (I can’t remember why now though. I think it was a 500 error). I downloaded the source code and extracted depot_r and it threw up a 500 error. I reinstalled Ruby, Rails and extracted it to a different location and still no difference. Can I just run script\server from the extracted depot application folder or does rails have a central listing of all applications created or somthing.

If it helps at all on the default Rails index page, the dropdown which normally shows all the server info like Rails versione etc. also shows a 500 error.

Is this because the Depot application was written for an earlier version of Rails or somthing?

Any help would be appreciated.

Generic-user-small
20 Jun 2006, 10:57
Fora User (865 posts)

Most likely a problem with your database setup. Investigate log/development.log for more details.

Generic-user-small
20 Jun 2006, 23:58
Fora User (865 posts)

Hello,

I’m very much a RoR novice so I may have missed something very basic here. As part of the checkout procedure, I added the validations in order.rb:

class Order < ActiveRecord::Base has_many :line_items

PAYMENT_TYPES = [ [“Check”, “check” ], [“Creidt cart”, “cc”], [“Purchase order”, “po”] ]

validates_presence_of :name, :address, :email, :pay_type validates_inclusion_of :pay_type, :in => PAYMENT_TYPES.map {|disp, value| value}

def add_line_items_from_cart(cart) cart.items.each do |item| li = LineItem.from_cart_item(item) line_items « li end end

end

Then, as suggested, I clicked the “Place Order” button without entering anything. All the fields were highlighted, but I did not get the error messages. I added something like: “logger.error flash[:notice]” to my store.rhtml and sure enough it comes out nil. Anyone know why the error messages might be missing from the flash?

Thanks for your help,

Mike Witt

Generic-user-small
30 Jun 2006, 15:56
Fora User (865 posts)

When I completed the part where the html for the shopping cart is replaced and the cart is given the blind_down visual effect, I notice that the cart first displays, then disappears, and then blinds down. Is that the normal behavior? It looks a bit off, so I wanted to check. Incidentally, here is my rjs code:

page[:cart].replace_html :partial => ‘cart’, :object => @cart page[:cart].visual_effect :blind_down if @cart.total_items == 1 page[:current_item].visual_effect :highlight, :startcolor => “#88ff88”, :endcolor => “#114411”

What I’d like this to do is for the replace_html and the blind_down to happen concurrently, but I have no idea how to make that happen. Anyone have any ideas?

Thanks, Mike Witt

Generic-user-small
20 Jun 2006, 23:58
Fora User (865 posts)

Ok, I figured this out. I left:

<%= error_messages_for 'order' %>

out of checkout.rhtml. I originally assumed that the line:

        <% if flash[:notice] -%>
            <div id="notice"><%= flash[:notice] %></div>
        <% end -%>

in store.rhtml was handling this. I guess validation errors do not go in the flash?

Mike Witt

Generic-user-small
23 Jun 2006, 15:47
Fora User (865 posts)

nm…resolved.

Generic-user-small
23 Jun 2006, 19:33
Fora User (865 posts)

I had the same issue here’s the fix.

In the depot.css file find:

store .entry .price{

color: #44a; font-weight: bold; margin-right: 2em; float: left; }

Replace it with:

store .entry .price{

color: #44a; font-weight: bold; margin-right: 2em; /* float: left; */ }

The float: left; is not needed and when you float that element in the div it renders to the left of the bottom border.

Enjoy!

Generic-user-small
23 Jun 2006, 19:34
Fora User (865 posts)

grrr…sorry about the formatting above…

comment out or remove the “float:left” property in the “#store .entry .price” style…

Generic-user-small
23 Jun 2006, 19:50
Fora User (865 posts)

Once you do the B4 iteration add_to_cart button you’ll want to uncomment or re-add the “float:left” property or it won’t render properly.

(though it still doesn’t render very well because for some reason the button doesn’t get the #store .entry .add_to_button style applied to it…)

so you get something like this…

$29.99 ———– |Add to Cart| ———–

Generic-user-small
23 Jun 2006, 19:51
Fora User (865 posts)

grrrrrr again! this formatting thing is killing me…

price button

there…grrr

Generic-user-small
23 Jun 2006, 19:52
Fora User (865 posts)

BAHHHHHHH

It still didn’t do it right…I need to use preview… I cannot make it look right…

basically what happens is that the price is just a tad higher than the button but they’re only roughly on the same line.

Generic-user-small
27 Jun 2006, 07:20
Fora User (865 posts)

In the sessions discussion where the environment.rb changes are made the first section about manipulating the commented out section is correct.

However 2 lines lower you show the old version of this file with the line commented out.

it should be

”# (create the session table with ‘rake db:session:create’) “

it currently is

”# (create the session table with ‘rake create_sessions_table’)”

NOTE: double quotes added to get around formatting issues with “opinion”

Just a minor typo issue!

Generic-user-small
27 Jun 2006, 07:18
Fora User (865 posts)

I don’t think parallellism is possible, but what you’re seeing shouldn’t be happening either. The replace_html call replaces content that should be hidden before the blind_down effect occurs. Are you sure that you’ve initially hidden the DIV containing the cart? (It might not show at first because it’s empty – you should check your CSS and style selectors.)

Generic-user-small
27 Jun 2006, 07:20
Fora User (865 posts)

Have you filed an erratum? Then you will be sure it meets the writer’s eye!

Generic-user-small
30 Jun 2006, 15:56
Fora User (865 posts)

You were right, it looks like it was programmer error!

I had hidden the div inside the cart partial instead of in the store layout.

Thanks for your help!

Generic-user-small
07 Feb 2007, 18:26
Fora User (865 posts)

I feel kind of dumb even having to ask this one, but I am not sure if I am adding the code from the example in the right place.

So I started chapter 12 with a working depot, added the ‘has_many :orders, :through => :line_items’ line to product.rb.

And on page 174, you run the generate controller info script, after which there is the ‘def who_bought …. end’ code. My question is where does this go?! There is no preface above it to specify the file, and there are only 2 files used before the working example.

I’ve tried adding it to product.rb, and just to say I tried it, I added it to the who_bought.rxml file. In both cases I get an error (and I tried 1-5 for the product ids)

http://localhost:3000/info/who_bought/1

NoMethodError in Info#who_bought

Showing app/views/info/who_bought.rxml where line #1 raised:

You have a nil object when you didn’t expect it! The error occured while evaluating nil.title

Extracted source (around line #1):

1: xml.order_list(:for_product => @product.title) do 2: for o in @orders 3: xml.order do 4: xml.name(o.name)

Generic-user-small
05 Jul 2006, 21:42
Fora User (865 posts)

D’oh - nevermind it goes in the controller. No idea why I blanked on that one.

Generic-user-small
07 Jul 2006, 01:34
Fora User (865 posts)

Greetings,

I’m having trouble with the functional test on p. 200 (PDF), test_login. Here’s a snippet of the output from running the tests:

1) Failure: test_login(LoginControllerTest) [test/functional/login_controller_test.rb:37]: Expected response to be a , but was <200>

I’ve read the code forwards and backwards for mistakes, I’ve tried to clear the session at the start of the test, I’ve tried clearing the sessions in the db (rake db:sessions:clear) and I’ve tried to restrart lighttpd, all to no avail. Has anyone else faced this problem and solved it?

Thanks, Craig

Generic-user-small
31 May 2007, 18:26
Fora User (865 posts)

Hello friends, I’m through until C1 and I have a problem there.

Whenever I click on the “Add to cart” button, I get a “NoMethodError”. Here is the stack trace from development.log.


Processing StoreController#add_to_cart (for 127.0.0.1 at 2006-07-11 00:05:23) [POST] Session ID: e3f1f8133e99d0022a63eade287755f0 Parameters: {“action”=>”add_to_cart”, “id”=>”2”, “controller”=>”store”} Product Load (0.000000) SELECT * FROM products WHERE (products.id = ‘2’) LIMIT 1

NoMethodError (You have a nil object when you didn’t expect it! You might have expected an instance of Array. The error occured while evaluating nil.«): /app/models/cart.rb:10:in add_product' /app/controllers/store_controller.rb:17:in add_to_cart’ —————————————————————————–

Cart.rb:

class Cart

attr_reader :items

def initialize
	@items = []
end

def add_product(product)
	@items<<product
end end

store_controller.rb:

class StoreController < ApplicationController

def index @products = Product.list_products end

def add_to_cart @cart=find_cart @product=Product.find(params[:id]) @cart.add_product(@product) end

private def find_cart session[:cart] ||= Cart.new end

end

I’m not sure what causes this error. I have been following all the instructions as given. Please help.

Thanks!

Generic-user-small
12 Jul 2006, 13:35
Fora User (865 posts)

Your definition of class Cart looks like this:

class Cart end

# some methods

That “end” on the first line of your class shouldn’t be there, as it’s causing you to define a class named Cart that has no methods. Move it the end of the class definition, after the methods.

Good luck, Craig

Generic-user-small
12 Jul 2006, 13:36
Fora User (865 posts)
  1. some methods

should have been a commented line in Ruby. The forum software did some fancy formatting with my pound sign (hash symbol).

Craig

Generic-user-small
18 Jul 2006, 19:21
Fora User (865 posts)

I’m sure the answer to this is simple but my googling has got me nowhere:

In the first few tests a new product is created and tested with assert product.valid? (or >assert !product.valid?). The first test using fixture data, however, uses assert !product.save Why use one and not the other? Would the valid method not work in this case and if not, why?

Thanks!!

Generic-user-small
06 Feb 2007, 02:33
Fora User (865 posts)

Pg. 74 uses a column type of :decimal which causes an error when rake db:migrate is run (see below). :decimal is not in the Rails documentation. Is this an error in the book? How can I get this example working?

C:\InstantRails\rails_apps\depot>rake db:migrate

(in C:/InstantRails/rails_apps/depot)

== AddPrice: migrating ========================================================

– add_column(:products, :price, :decimal, {:precision=>8, :default=>0, :scale=>2})

rake aborted!

You have a nil object when you didn’t expect it!

You might have expected an instance of Array.

The error occured while evaluating nil.[]

Generic-user-small
22 Jul 2006, 07:11
Fora User (865 posts)

It looks like :decimal is a fairly new column type. Via “PragDave”:http://blogs.pragprog.com/cgi-bin/pragdave.cgi/Tech/Ruby/DecimalColumns.rdoc

I’ll substitute :integer until my Rails dev setup supports :decimal columns.

Generic-user-small
23 Jul 2006, 18:34
Fora User (865 posts)

You have the newest PDF… To use :decimal as the book intends you have to have your project on edge rails.

The “Sitepoint Blog post”:http://www.sitepoint.com/blogs/2006/07/11/installing-and-managing-edge-rails/ has a decent write-up on how to get a project on to edge rails. However, not all edge versions are stable or fully functional so caveat emptor etc etc.

Generic-user-small
25 Jul 2006, 05:40
Fora User (865 posts)

Thanks for the tip and the link.

Generic-user-small
28 Jul 2006, 20:25
Fora User (865 posts)

I have been trying to create a “remove from cart” method in the depot application and am having trouble.

(in the cart controller)

def remove_item @cart.remove_cart_item(params[:id]) end

The problem I’m having is writing a proper remove_cart_item method in the model.

Can anybody help me with this?

Generic-user-small
31 Jul 2006, 19:01
Fora User (865 posts)

And if we’re not on edge, is it ok to continue using :integer here?

Generic-user-small
03 Aug 2006, 06:30
Fora User (865 posts)

heyotwell:

Yes you can.

If you are using the tutorial then I’d probably get rails running version of Edge. Or revert to the older PDF if you have it handy. Obviously there needs to be more documentation of the process in the book; or hopefully we will get :decimal in stable in the near future.

:integer is not a problem if you just want to follow along and disregard some of the validation etc.

cheers

Generic-user-small
04 Aug 2006, 09:08
Fora User (865 posts)

Hi All,

Just need some clarification here ?

Rails doesn’t understand decimals ? Or does something else not understand decimals ?

So if I develop a eCommerce site everthing will look like:

29 and not 29.95 if I want decimal places ?

TIA - Dave Porter

Generic-user-small
15 Aug 2006, 06:10
Fora User (865 posts)

I’m trying to get the highlight code to work with RJS from page 131. However I’m getting a JavaScript error “current_item has no properties” on the else conditions because the element with id=”current_item” doesn’t exist until at least one item is added to the cart of that type. Is this an oversight on the part of the author or am I doing something wrong?

Generic-user-small
11 Aug 2006, 21:59
Fora User (865 posts)

In the Task A: Product Maintenance

I tried to use the: depot>rake db:migrate command to check my MySql connection, I get the following error

(in C:/Documents and Settings/xxx/My Documents/xxxx/depot) rake aborted! undefined method `each’ for #

Any ideas what this might be?

I have checked my yml file that the password and user name is correct and I can initiate a connection to my database with the mysql command.

Generic-user-small
15 Aug 2006, 01:27
Fora User (865 posts)

I was having a lot of trouble with this as well I discovered that for the _cart_item.rhtml partial if I used:

<% if cart_item.equal?(@current_item) %>

instead of

<% #if cart_item == @current_item %>

it seems to work. I wonder if “==” was overwritten in a class file causing it to fail. After all the only difference between the two according to the docs is:

Unlike ==, the equal? method should never be overridden by subclasses: it is used to determine object identity (that is, a.equal?(b) iff a is the same object as b).

Generic-user-small
15 Aug 2006, 06:10
Fora User (865 posts)

Whoops, I found the source of my error. For CartItems I used the generate script causing it to make use of ActiveRecord which definitely overwrites “==”. Removing ActiveRecord solved the problem for me, for the past hour I was debugging the javascript!

Generic-user-small
15 Aug 2006, 06:10
Fora User (865 posts)

Whoops, I found the source of my error. For CartItems I used the generate script causing it to make use of ActiveRecord which definitely overwrites “==”. Removing ActiveRecord solved the problem for me, for the past hour I was debugging the javascript!

Generic-user-small
15 Aug 2006, 13:05
Fora User (865 posts)

Hi Everyone,

So I worked my way through the Depot application, and I’ve been playing around with various ‘enhancements’ to see if I’ve got the hang of the concepts presented. One thing I ran into, however, was in creating an action to edit an existing user account in the system.

I’ve converted the add_user view to use a partial, named _form.rhtml, which works as expected. But, when I bring up the user for editing, I’m prompted for the password and password confirmation. When I’m just editing the user’s name, I may not want to change the password, but if I leave the password and confirm fields blank, the form returns with an error (failing the validation in user.rb on the password and confirm fields) and will not save.

Any thoughts on how I can handle this?

Generic-user-small
17 Aug 2006, 03:30
Fora User (865 posts)

I’m having the same problem, and not sure what to do to troubleshoot. I checked and don’t have an extraneous end at the end of my class declaration in cart.rb.

Any help appreciated.

Thanks

Generic-user-small
13 Sep 2007, 16:00
Fora User (865 posts)

Hello everybody,

I get the following error when clicking the “Add to cart”-button:

RJS Error: TypeError $(“cart”) has no properties

Any ideas?

Thanks, Peter

Generic-user-small
04 Sep 2007, 17:33
Fora User (865 posts)

In the homework section of the AJAX chapter I’m having problems making the cart disappear using Sciptaculous’ blind_up feature. The blind_down works great according the code examples in the chapter. Using form_remote_tag I can successfully empty the cart but I don’t see the effect unless I refresh the page. Here are some snippets from my changes:

From _cart.rhtml:

<%= form_remote_tag :url => { :action => :empty_cart } %> <%= submit_tag “Empty cart” %> <%= end_form_tag %>

From add_to_cart.rjs:

page[:cart].visual_effect :blind_up if @cart.items.empty?

Thanks,

Mike

Generic-user-small
24 Aug 2006, 19:51
Fora User (865 posts)

I had the same problem with the :decimal field and followed the instructions to link to the latest version of Rails on Page 236. The example says to run an “svn propset …..”, but I can’t find any executable named svn from my InstantRails install. Did I botch something during my install or are the instructions missing something?

Generic-user-small
24 Aug 2006, 22:52
Fora User (865 posts)

Dave:

If you have a recent book then you will need to adapt the tutorial to use two fields for decimal storage. Decimals are part of edge:rails, but have not been released into the wild yet. I assume this is slated for 1.2.

ScottS917:

‘svn’ is the client executable for the Subversion versioning software. You can see more at:

“Subversion”:http://subversion.tigris.org/

Also, you could do a ‘rake rails:freeze:edge’ as noted on the wiki site:

“RailsWiki”:http://wiki.rubyonrails.org/rails/pages/EdgeRails

Generic-user-small
25 Aug 2006, 00:46
Fora User (865 posts)

Hey Mike,

I happen to be at that exact part of the book as well. I haven’t nailed it yet either. I didn’t try using the form_remote_tag though, I’ll have to take a stab at that.

I just took out the “redirect_to_index” in the empty_cart method in store_controller.rb. The browser then told me I was missing empty_cart.rjs, so I created one and put in the page[:cart].visual_effect :blind_up if @cart.items.empty?. I then get a nil error on total_items and that’s where I’m stuck.

Try moving the page[:cart].visual_effect :blind_up if @cart.items.empty? to a new file called empty_cart.rjs and see if that works for your predicament.

Anyone else figure out a way to empty and blind_up the cart?

-=Randy

Generic-user-small
26 Aug 2006, 00:40
Fora User (865 posts)

h2. I Got it working!

I changed the Empty Cart button code to: (percent signs won’t post here, so they are missing)
<%= form_remote_tag :url => { :action => :empty_cart } %>
<%= submit_tag “Empty Cart” %>
<%= end_form_tag %>
(thanks for the clue Mike!)

I then created a new .rjs file, app/view/store/empty_cart.rjs:
page[:cart].replace_html :partial => ‘cart’, :object => @cart
page[:cart].visual_effect :blind_up if @cart.items.empty?

and finally, changed the empty_cart method in app/controllers/store_controller.rb:
def empty_cart
session[:cart] = nil
@cart = find_cart
redirect_to_index unless request.xhr?
end
(if I place ‘@cart = find_cart’ before ‘session[:cart] = nil’, then I have to hit the Empty Cart button twice to see the cart empty and then blind_up)

It would be nice to delay the blind_up one second so the visitor can see that the cart displays as empty. I can see it if I know where to look, but a visitor may miss it and not realize.

Generic-user-small
28 Aug 2006, 01:43
Fora User (865 posts)

Randy,

Thanks for the clue. It was as simple as moving the Javascript syntax into empty_cart.rjs and it started working.

Mike

Generic-user-small
03 Sep 2006, 20:49
Fora User (865 posts)

Yesterday I was followed along in the book and got to the point where I working on the admin, added the code that validates that the fields, and added the CSS file, and can see all of the products listed (around pdf page 91). I turned off the computer, came back to launch rails the next day. My demo program works, but when I quit that and try to run depot, I can get to the rails defaul page, but when I try to go to the /admin, I get Not Found `/admin/’ not found. WEBrick/1.3.1 (Ruby/1.8.4/2005-12-24) at localhost:3000

Generic-user-small
02 Sep 2006, 18:32
Fora User (865 posts)

“Once we log someone in, we can then check to see if there’s a URI stored in the session and redirect to it if so. We also need to clear down that stored URI once used.”

Shouldn’t this code work (for the most part) if I change the redirect_to call (see below) to the following?

  FROM:   redirect_to(uri || { :action => "index" })  

    TO:   redirect_to(uri)

If I do this I start getting errors. Also, I tried to use this style of redirect after changing the code to use a non application.rb controller authentication scheme. When I do that, the redirect_to to the original uri causes some problems. I am just a novice with Ruby on Rails. My current understanding and experimentation with this style of “post login redirect to original uri” is filled with confusion. I can’t seem to get consistency when switching from authentication which is contained in the user created controller and authentication which is handled by the application.rb controller. You can see the various differences by comparing the depot code with the authenication scheme in the “rails recipes” book.

Original code suggested on page 155:

if user

session[:user_id] = user.id

uri = session[:original_uri]

session[:original_uri] = nil

redirect_to(uri   { :action => “index” })

else

flash[:notice] = “Invalid user/password combination”

end

Any discussion would be helpful to me… Thanks,

Generic-user-small
02 Sep 2006, 18:54
Fora User (865 posts)

I installed the latest gems using InstantRails in the cmd window. Inside the app itself:

C:\InstantRails\rails_apps\depot>gem update rails –include-dependencies

Then I am able to run the command:

rails_apps\depot>rake rails:freeze:edge

I can now migrate the proper Decimal fields. I got so sick of trying to migrate that over and over, I just combined migration 1-2 calling it 001_create_products.rb:

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 t.column :price, :decimal, :precision => 8, :scale => 2, :default => 0.00 end end

def self.down drop_table :products end end

Generic-user-small
03 Sep 2006, 20:49
Fora User (865 posts)

I can get the app to run under Locomotive, but not by doing ruby script/server. I get the default Welcome page either way.

Generic-user-small
16 Nov 2006, 01:54
Fora User (865 posts)

I have reached this point in the book: Add a link next to each item in the cart. When pressed it should invoke an action to decrement the quantity of the item, deleting it from the cart when the quantity reaches zero. Get it working without using Ajax first, then add in the Ajax goodness.

I have managed to decrement the quantity, and make decrementing impossible when the count hits 0, but I can’t get the product to disappear from the cart.

My code: store_controller.rb: def remove_from_cart begin @product = Product.find(params[:id]) rescue logger.error(“Attempt to access invalid product #{params[:id]}”) redirect_to_index(“Invalid product”) else @cart = find_cart @current_item = @cart.remove_product(@product) redirect_to_index unless request.xhr? end end

cart.rb: def remove_from_cart begin @product = Product.find(params[:id]) rescue logger.error(“Attempt to access invalid product #{params[:id]}”) redirect_to_index(“Invalid product”) else @cart = find_cart @current_item = @cart.remove_product(@product) redirect_to_index unless request.xhr? end end

cart_item.rb: def decrement_quantity if @quantity == 0 else @quantity -= 1 end end

What I want to do now is to remove the product from the cart (and the session) when it hits 0. How do I solve this?

Generic-user-small
06 Sep 2006, 16:27
Fora User (865 posts)

I’m having the same problem.

I know that the current item’s tr is getting tagged with the “current_item” id, but the visual_effect call in the RJS template is not working. (The replace_html call is working for me, since the cart gets updated in the sidebar.) Also, if I tell RJS to highlight a static element, such as “searchbox”, nothing happens.

I’m guessing you figured out what the problem was (since you posted almost 3 months ago) and that it was something trivial (since no one else has bothered to comment).

Generic-user-small
07 Sep 2006, 14:24
Fora User (865 posts)

So I tried to move on to the next step (hide cart, blind down when first item added) and the blind down isn’t working either. My visual_effect calls are getting ignored.

Generic-user-small
07 Sep 2006, 15:24
Fora User (865 posts)

Solved. I originally built this app from the first-ed book with an older version of Rails. I had already made sure Rails was up-to-date, but the javascript files weren’t. “rake rails:update” to the rescue.

Generic-user-small
22 Jan 2007, 12:47
Fora User (865 posts)

I’m confused. I’ve been following the directions for the depot and everything worked (even the highlighting) until I got to the blind down effect for the ajaxified cart. I get this error in my terminal: ActionView::TemplateError (undefined method `sum’ for #) on line #3 of app/views/store/add_to_cart.rjs: the @cart.total_items function uses the built in sum method -- how can a built in method be undefined? Thanks for any help!

Generic-user-small
14 Sep 2006, 03:17
Fora User (865 posts)

Having an issue here. Anytime I had, change, delete a method in my cart.rb model it appears as if I had done nothing when interfacing with the website until I restart webrick.

Further explained.. If I add a new method to cart.rb (which I was adding total_price) and then called that in add_to_cart.rhtml with @cart.total_price it tells me ‘undefined method total_price’, however, if I restart webrick then it will magically work. This happens with everything that I change in cart.rb. I have even tried doing rake db:sessions:clear, and that didn’t fix it.

Any help would be great…hopefully I posted this to the correct spot.

Generic-user-small
14 Sep 2006, 03:17
Fora User (865 posts)

Found the problem here, I’m really surprised this hasn’t been caught yet..

But if your model is not a subclass of ActiveRecord::Base then it will not be reloaded automatically only once when the server initially starts.

If you want Rails to reload a model that isn’t a subclass of ActiveRecord::Base, you used to add the following declaration in a controller:

model :my_model That syntax is now deprecated in favor of adding the following declaration in your model file:

include Reloadable

That’s from here: http://clarkware.com/cgi/blosxom/2006/03/28

Generic-user-small
16 Sep 2006, 19:23
Fora User (865 posts)

Your post really helped me; I’m fairly new with this stuff as well. I have an ugly flicker that takes place when the blind_down initially takes place and then when blind_up finishes its action. There is no flicker when the highlight fade takes place. This is in the IE 6 and Avante browsers.

Generic-user-small
19 Sep 2006, 16:45
Fora User (865 posts)

mines pretty close to what you have there except I did this in cart.rb:

def remove_item(itemid)
  hold = []  # this is a temp var to hold cart
  for item in @items
    if item.id.to_s == itemid
      unless item.quantity == 1
        item.decrement_quantity
        hold << item
      end
    else
      hold << item
    end
  end
  @items = hold
end

on the for and if line there is supposed to be an “==” but for some reason comment wouldn’t show it.

I am somewhat new to rails so if someone has a better option please let me know.

Generic-user-small
21 Sep 2006, 09:35
Fora User (865 posts)

Thanks for your reply. I tried this:

def remove_product(product) hold = [] # this is a temp var to hold cart for item in @items if item.id.to_s == product unless item.quantity == 1 item.decrement_quantity hold « item end else hold « item end end @items = hold

Plus an end after @items = hold.

However, when using this it didn’t even decrement the quantity. Could you post the whole code for this operation?

Generic-user-small
23 Sep 2006, 15:23
Fora User (865 posts)

I’m working my way through the depot application and have realized that the inject method described on page 106 is incorrect.

Coding the total_price method as described will only give you the total price for a single instance of each item in the cart.

I’ve corrected the function in my own code by multiplying item.price by item.quantity and that seems to be working fine.

def total_price @items.inject(0) { |sum, item| sum + item.price*item.quantity } end

Generic-user-small
22 Sep 2006, 23:43
Fora User (865 posts)

I had to change the total_items function to

def total_items @items.inject(0) { |sum, item| sum + item.quantity } end

to be able to use the sum. The old way threw errors at me that “sum” wasn’t defined for “Array” :

Showing app/views/store/_cart.rhtml where line #8 raised: undefined method `sum’ for # Extracted source (around line #8): 8: <td><%%= cart.total_items %%></td>

(I added the total_items output to the cart table to see what it contains.)

Generic-user-small
22 Sep 2006, 22:37
Fora User (865 posts)

I am also having this problem. I’ve verified that all the files look correct. It seems that the cart is not created correctly (since I think that the

@items « product

is trying to add product to items, which is nil. I am not using the edge rails, I am using the current version instead.

Generic-user-small
22 Sep 2006, 23:41
Fora User (865 posts)

You have to be sure to have a method ‘decrement_quantity’ in there which will just take it down one.

Generic-user-small
22 Sep 2006, 23:43
Fora User (865 posts)

I had the same problem; same solution.

Generic-user-small
23 Sep 2006, 15:00
Fora User (865 posts)

This what I did.

_cart_item.rhtml:

<%= form_remote_tag :url=>{ :action=>:decrement_cart_quantity, :id=>cart_item.product} %> <%= submit_tag “Decrement” %> <%= end_form_tag %> </td>

cart.rb:

def decrement_product_quantity(product_id)

current_item = @items.find {|item| item.product.id == product_id.to_i }

if current_item.quantity == 1

  @items.delete(current_item)

  @items.compact

  current_item = nil

else

  current_item.decrement_quantity

end

current_item

end

Note that I had to convert product_id from the form to an integer. Is there a way to have it come in that way?

Also note that “compact” method call so collapse any gaps in the items array.

Generic-user-small
23 Sep 2006, 15:23
Fora User (865 posts)

Actually, no. The method call item.price includes logic to determine total price for a product that takes into account the quantity ordered.

Generic-user-small
25 Sep 2006, 07:55
Fora User (865 posts)

Great! Got it working now with this code:

cart.rb:

def remove_product(product) current_item = @items.find {|item| item.product == product } if current_item.quantity == 1 @items.delete(current_item) @items.compact current_item = nil else current_item.decrement_quantity end current_item end

cart_item.rb:

def decrement_quantity @quantity -= 1 end

store_controller.rb:

def remove_from_cart begin @product = Product.find(params[:id]) rescue logger.error(“Attempt to access invalid product #{params[:id]}”) redirect_to_index(“Invalid product”) else @cart = find_cart @current_item = @cart.remove_product(@product) redirect_to_index unless request.xhr? end end

_cart_item.rhtml:

<%= link_to_remote “[-]”, :url => { :action => :remove_from_cart, :id => cart_item.product } %>

Watch out for missing == in remove_product between item.product EQUALS product, and at if current_item.quantity EQUALS 1

Generic-user-small
26 Sep 2006, 14:29
Fora User (865 posts)

I don’t have much of a description. I copied and pasted the code for “class Product < ActiveRecord::Base” and I am able to add blank records left and right. I can also add items with prices of “a” (which convert themselves into 0.00.) I’m not sure where to start to look? Any help would be appreciated.

Generic-user-small
26 Sep 2006, 02:42
Fora User (865 posts)

in cart.rb, change these functions to:

def total_items @items.inject(0) {|sum, item| sum + item.quantity} end

def total_price @items.inject(0) { |sum, item| sum + item.price } end end

Generic-user-small
26 Sep 2006, 14:29
Fora User (865 posts)

Well, magically things started working this morning. I had tried to shutdown the server and start it back up last night and that did not work. This morning I turned on the server and everything worked. Very weird.

Generic-user-small
13 Dec 2006, 05:33
Fora User (865 posts)

Code: t.column :price, :decimal, :percision => 8, :scale => 2, :default => 0.00

creates a MySQL decimal(10,0) with a default value of 0.

shouldn’t it create a decimal(8,2) with a default of 0.00?

when I manually create a decimal(8,2) I get the expected results from my app, decimal(10,0) is not what I want.

am i missing anything? can anyone help?

while I’m asking, anyone know a way to specify unique constraints in the migration short of a native sql execute or plugin?

many thanks,

josh

Generic-user-small
29 Sep 2006, 23:42
Fora User (865 posts)

Still haven’t figured out the decimal issue but for those also wondering about setting unique in a migration:

add_index :users, :username, :unique => true, :index => true

Generic-user-small
01 Oct 2006, 01:02
Fora User (865 posts)

You need to use Edge Rails that fixed the issue. One revision which I used and works for this matter is 5195. To use this revision go to your depot folder and run

rake rails:freeze:edge REVISION=5195

Also, check for errors. If there is any, probably there is a conflict with your firewall. I had to switch off mine while doing this.

Hope this helps.

Generic-user-small
13 Mar 2007, 08:13
Fora User (865 posts)

I’m stuck trying to make the http://localhost:3000/login/add_user work.

I have tried Edge Rails [Revision 5206] but that does not solve the problem…

Can anyone help? Thanks!

NoMethodError in Login#add_user

Showing app/views/login/add_user.rhtml where line #16 raised: 

undefined method `password' for #<User:0x3c9d820>

Extracted source (around line #16):

13: 
14: 			<p>
15: 				<label for="user_password">Password:</label>
16: 				<%= form.password_field :password, :size => 40 %>
17: 			</p>
18: 
19: 			<p>

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

#{RAILS_ROOT}/vendor/rails/activerecord/lib/active_record/base.rb:1839:in `method_missing'
#{RAILS_ROOT}/vendor/rails/actionpack/lib/action_view/helpers/form_helper.rb:354:in `value_before_type_cast'
#{RAILS_ROOT}/vendor/rails/actionpack/lib/action_view/helpers/form_helper.rb:342:in `value_before_type_cast'
#{RAILS_ROOT}/vendor/rails/actionpack/lib/action_view/helpers/form_helper.rb:257:in `to_input_field_tag'
#{RAILS_ROOT}/vendor/rails/actionpack/lib/action_view/helpers/form_helper.rb:165:in `password_field'
#{RAILS_ROOT}/vendor/rails/actionpack/lib/action_view/helpers/form_helper.rb:428:in `password_field'
#{RAILS_ROOT}/app/views/login/add_user.rhtml:16:in `_run_rhtml_47app47views47login47add_user46rhtml'
#{RAILS_ROOT}/app/views/login/add_user.rhtml:8:in `_run_rhtml_47app47views47login47add_user46rhtml'
Generic-user-small
03 Oct 2006, 06:09
Fora User (865 posts)

The issue is solved by my fellow colleague.

Strangely, he did a gem install mysql to update to the latest version and everything works fine now. =)

Generic-user-small
05 Oct 2006, 20:22
Fora User (865 posts)

Thanks for the reply.

I am already on Rails Edge 5228. Just droped back to 5195 to check and same problem so that didn’t fix the issue.

The problem isn’t with decimal in migrations failing, the problem is that the decimal percision isn’t setting properly.

Code: @t.column :price, :decimal, :percision => 8, :scale => 2, :default => 0.00@

CREATES: a MySQL decimal(10,0) with a default value of 0.

NOT: a MySQL decimal(8,2) with a default of 0.00

when I manually create a decimal(8,2) I get the expected results from my app, decimal(10,0) is not what I want.

Does this make sense?

Generic-user-small
14 Oct 2006, 01:59
Fora User (865 posts)

Does anyone know if return false needs to be explicitly stated after the redirect in the authorize method (this is in iteration F3)? If I do not add this I get a double render/redirect error. From the error it seems that the “requested” action still runs after the authorize method (even if there is a redirect). I guess this causes sending the user to two different actions? In this case that would be login/login from the authorize method and admin/list from the url. There is no mention (at least that I can see) of return false in either the text or supplied code. Any help much appreciated. Thx.

Generic-user-small
13 Oct 2006, 20:39
Fora User (865 posts)

Hi all,

I’m getting a strange error when I click the “Checkout” button after working through E1:

=================================

NoMethodError in Store#checkout

Showing app/views/store/checkout.rhtml where line #26 raised:

undefined method `email’ for #

Extracted source (around line #26):

23: 24: <p> 25: E-Mail: 26: <%= form.text_field :email, :size => 40 %> 27: </p> 28: 29: <p>

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

vendor/rails/activerecord/lib/active_record/base.rb:1845:in method_missing' vendor/rails/actionpack/lib/action_view/helpers/form_helper.rb:354:in value_before_type_cast’ vendor/rails/actionpack/lib/action_view/helpers/form_helper.rb:342:in value_before_type_cast' vendor/rails/actionpack/lib/action_view/helpers/form_helper.rb:257:in to_input_field_tag’ vendor/rails/actionpack/lib/action_view/helpers/form_helper.rb:160:in text_field' vendor/rails/actionpack/lib/action_view/helpers/form_helper.rb:428:in text_field’ #{RAILS_ROOT}/app/views/store/checkout.rhtml:26:in _run_rhtml_47app47views47store47checkout46rhtml' #{RAILS_ROOT}/app/views/store/checkout.rhtml:13:in _run_rhtml_47app47views47store47checkout46rhtml’

vendor/rails/activerecord/lib/active_record/base.rb:1845:in method_missing' vendor/rails/actionpack/lib/action_view/helpers/form_helper.rb:354:in value_before_type_cast’ vendor/rails/actionpack/lib/action_view/helpers/form_helper.rb:342:in value_before_type_cast' vendor/rails/actionpack/lib/action_view/helpers/form_helper.rb:257:in to_input_field_tag’ vendor/rails/actionpack/lib/action_view/helpers/form_helper.rb:160:in text_field' vendor/rails/actionpack/lib/action_view/helpers/form_helper.rb:428:in text_field’ vendor/rails/actionpack/lib/action_view/helpers/form_helper.rb:149:in fields_for' vendor/rails/actionpack/lib/action_view/helpers/form_helper.rb:127:in form_for’ vendor/rails/actionpack/lib/action_view/base.rb:326:in compile_and_render_template' vendor/rails/actionpack/lib/action_view/base.rb:301:in render_template’ vendor/rails/actionpack/lib/action_view/base.rb:260:in render_file' vendor/rails/actionpack/lib/action_controller/base.rb:788:in render_file’ vendor/rails/actionpack/lib/action_controller/base.rb:694:in render_with_no_layout' vendor/rails/actionpack/lib/action_controller/layout.rb:247:in render_without_benchmark’ vendor/rails/actionpack/lib/action_controller/benchmarking.rb:50:in render' /usr/local/lib/ruby/1.8/benchmark.rb:293:in measure’ vendor/rails/actionpack/lib/action_controller/benchmarking.rb:50:in render' vendor/rails/actionpack/lib/action_controller/base.rb:1071:in perform_action_without_filters’ vendor/rails/actionpack/lib/action_controller/filters.rb:628:in call_filter' vendor/rails/actionpack/lib/action_controller/filters.rb:615:in perform_action_without_benchmark’ vendor/rails/actionpack/lib/action_controller/benchmarking.rb:66:in perform_action_without_rescue' /usr/local/lib/ruby/1.8/benchmark.rb:293:in measure’ vendor/rails/actionpack/lib/action_controller/benchmarking.rb:66:in perform_action_without_rescue' vendor/rails/actionpack/lib/action_controller/rescue.rb:81:in perform_action’ vendor/rails/actionpack/lib/action_controller/base.rb:427:in process_without_filters' vendor/rails/actionpack/lib/action_controller/filters.rb:620:in process_without_session_management_support’ vendor/rails/actionpack/lib/action_controller/session_management.rb:114:in process' vendor/rails/actionpack/lib/action_controller/base.rb:330:in process’ vendor/rails/railties/lib/dispatcher.rb:41:in dispatch' vendor/rails/railties/lib/webrick_server.rb:110:in handle_dispatch’ vendor/rails/railties/lib/webrick_server.rb:76:in service' /usr/local/lib/ruby/1.8/webrick/httpserver.rb:104:in service’ /usr/local/lib/ruby/1.8/webrick/httpserver.rb:65:in run' /usr/local/lib/ruby/1.8/webrick/server.rb:173:in start_thread’ /usr/local/lib/ruby/1.8/webrick/server.rb:162:in start_thread' /usr/local/lib/ruby/1.8/webrick/server.rb:95:in start’ /usr/local/lib/ruby/1.8/webrick/server.rb:92:in start' /usr/local/lib/ruby/1.8/webrick/server.rb:23:in start’ /usr/local/lib/ruby/1.8/webrick/server.rb:82:in start' vendor/rails/railties/lib/webrick_server.rb:63:in dispatch’ vendor/rails/railties/lib/commands/servers/webrick.rb:59 /usr/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in require' vendor/rails/activesupport/lib/active_support/dependencies.rb:364:in require’ vendor/rails/railties/lib/commands/server.rb:39 script/server:3

vendor/rails/activerecord/lib/active_record/base.rb:1845:in method_missing' vendor/rails/actionpack/lib/action_view/helpers/form_helper.rb:354:in value_before_type_cast’ vendor/rails/actionpack/lib/action_view/helpers/form_helper.rb:342:in value_before_type_cast' vendor/rails/actionpack/lib/action_view/helpers/form_helper.rb:257:in to_input_field_tag’ vendor/rails/actionpack/lib/action_view/helpers/form_helper.rb:160:in text_field' vendor/rails/actionpack/lib/action_view/helpers/form_helper.rb:428:in text_field’ #{RAILS_ROOT}/app/views/store/checkout.rhtml:26:in _run_rhtml_47app47views47store47checkout46rhtml' vendor/rails/actionpack/lib/action_view/helpers/form_helper.rb:149:in fields_for’ vendor/rails/actionpack/lib/action_view/helpers/form_helper.rb:127:in form_for' #{RAILS_ROOT}/app/views/store/checkout.rhtml:13:in _run_rhtml_47app47views47store47checkout46rhtml’ vendor/rails/actionpack/lib/action_view/base.rb:326:in compile_and_render_template' vendor/rails/actionpack/lib/action_view/base.rb:301:in render_template’ vendor/rails/actionpack/lib/action_view/base.rb:260:in render_file' vendor/rails/actionpack/lib/action_controller/base.rb:788:in render_file’ vendor/rails/actionpack/lib/action_controller/base.rb:694:in render_with_no_layout' vendor/rails/actionpack/lib/action_controller/layout.rb:247:in render_without_benchmark’ vendor/rails/actionpack/lib/action_controller/benchmarking.rb:50:in render' /usr/local/lib/ruby/1.8/benchmark.rb:293:in measure’ vendor/rails/actionpack/lib/action_controller/benchmarking.rb:50:in render' vendor/rails/actionpack/lib/action_controller/base.rb:1071:in perform_action_without_filters’ vendor/rails/actionpack/lib/action_controller/filters.rb:628:in call_filter' vendor/rails/actionpack/lib/action_controller/filters.rb:615:in perform_action_without_benchmark’ vendor/rails/actionpack/lib/action_controller/benchmarking.rb:66:in perform_action_without_rescue' /usr/local/lib/ruby/1.8/benchmark.rb:293:in measure’ vendor/rails/actionpack/lib/action_controller/benchmarking.rb:66:in perform_action_without_rescue' vendor/rails/actionpack/lib/action_controller/rescue.rb:81:in perform_action’ vendor/rails/actionpack/lib/action_controller/base.rb:427:in process_without_filters' vendor/rails/actionpack/lib/action_controller/filters.rb:620:in process_without_session_management_support’ vendor/rails/actionpack/lib/action_controller/session_management.rb:114:in process' vendor/rails/actionpack/lib/action_controller/base.rb:330:in process’ vendor/rails/railties/lib/dispatcher.rb:41:in dispatch' vendor/rails/railties/lib/webrick_server.rb:110:in handle_dispatch’ vendor/rails/railties/lib/webrick_server.rb:76:in service' /usr/local/lib/ruby/1.8/webrick/httpserver.rb:104:in service’ /usr/local/lib/ruby/1.8/webrick/httpserver.rb:65:in run' /usr/local/lib/ruby/1.8/webrick/server.rb:173:in start_thread’ /usr/local/lib/ruby/1.8/webrick/server.rb:162:in start_thread' /usr/local/lib/ruby/1.8/webrick/server.rb:95:in start’ /usr/local/lib/ruby/1.8/webrick/server.rb:92:in start' /usr/local/lib/ruby/1.8/webrick/server.rb:23:in start’ /usr/local/lib/ruby/1.8/webrick/server.rb:82:in start' vendor/rails/railties/lib/webrick_server.rb:63:in dispatch’ vendor/rails/railties/lib/commands/servers/webrick.rb:59 /usr/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in require' vendor/rails/activesupport/lib/active_support/dependencies.rb:364:in require’ vendor/rails/railties/lib/commands/server.rb:39 script/server:3

Request

Parameters: None

Show session dump


:cart: !ruby/object:Cart items: - !ruby/object:CartItem product: !ruby/object:Product attributes: image_url: /images/auto.jpg title: Pragmatic Project Automation price: “29” id: “1” description: |- <p> Pragmatic Project Automation shows you how to improve the consistency and repeatability of your project’s procedures using automation to reduce risk and errors. </p> <p> 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. </p> quantity: 1 flash: !map:ActionController::Flash::FlashHash {}

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

=================================

I know that’s a lot to go through, but I’m not sure why I’m getting this error. I looks similar to the “Password” error mentioned a few posts earlier, but I tried gem installing mysql again with no result. Any suggestions of where I may have gone wrong? Thanks in advance!

Best, J. Kyle

Generic-user-small
13 Oct 2006, 20:32
Fora User (865 posts)

lol

I left the Email column out of my database migration in 005_create_orders.rb.

I’m going to try to another migration and see if it works.

Sorry for the false alarm.

J. Kyle

Generic-user-small
13 Oct 2006, 20:39
Fora User (865 posts)

It worked. Lesson to all: make sure your code matches your database :)

Generic-user-small
14 Oct 2006, 01:51
Fora User (865 posts)

I remember encountering your problem, while trying to resolve the Decimal problem and somehow fixed that.

One more thing which is important which solved another of my bug is to do

gem install mysql
rake rails:freeze:edge REVISION=5206
rake rails:update

Updating the mysql driver could be the key.

Generic-user-small
14 Oct 2006, 01:59
Fora User (865 posts)

Not sure about this, but it works in my code (following the book) without returning false.

Generic-user-small
18 Dec 2006, 12:48
Fora User (865 posts)

I’m very new to rails, ruby, AJAX, all that jazz. My background is Flash coding and interface design, so I’ve been going through this book with a lot of enthusiasm. However, I’m COMPLETELY stuck on one of the bonus activities in the Add A Dash of AJAX chapter and was wondering if anyone could give me a clue.

The task is to add a visual_effect :grow into the act of adding a new product to the AJAXy cart. Adding the grow effect in the rjs template was easy enough, but without hiding the initial state of the partial it appears just before the effect and there’s a nasty blip. The text mentions you need to hide the initial state, land that’s where I’m lost. I’ve tried adding style=”display: none” to the <tr> of the item in the _cart_item partial view IF it’s the ‘current_item’, but then the item remains completely hidden.

Any help would be much appreciated. Since I’m new to this, a very simple solution may not occur to me. Anyway, thanks in advance.

Generic-user-small
19 Oct 2006, 00:45
Fora User (865 posts)

Hello all,

I’m working my way through chapter 11 and I’m having problems with the console section. When I attempt to bring up the console I get the following error:

/usr/lib/ruby/1.8/irb/completion.rb:10:in `require’: No such file to load – readline (LoadError)

So, it looks like ruby is not able to find the readline file. Does anyone know how to solve this problem?

Elliot

Generic-user-small
19 Oct 2006, 16:51
Fora User (865 posts)

Perhapse I should simplify my question? Can anyone suggest a good method for hiding the initial state of a partial to remove the flicker before a visual_effect such as :grow?

Generic-user-small
20 Oct 2006, 02:52
Fora User (865 posts)

My cart is based on the AWDwR 2nd edition. Works great! Thanks!

I have a discount structure for product that is based on quantity …..not percentage (all my products are the same price).

To total my cart items price I am using the inject method in the cart model:

def total_price @items.inject(0) { |sum, item| sum + item.price } _ and then_ sum - 100 (or whatever is called) end

which displays with:

Total <%= number_to_currency(cart.total_price) %> To modify I'll be subtracting a fixed amout from the result of the inject Where should/can I modify the 'total_price'? _I want to subtract an amount from the 'sum' but I can't figure out how to get at it._ fred = 100 @items.inject(0) { |sum, item| sum + item.price } - fred _This of course didn't work...but that's what I'm looking for.._ Thanks Chas
Generic-user-small
22 Oct 2006, 11:25
Fora User (865 posts)

I have used this method, anticipating having a remove all link sometime later.

def remove_one(product) cart_item = @items.find {|item| item.product == product} cart_item.decrement_quantity if cart_item.quantity < 1 remove_all(product) end end

def remove_all(product) @items.delete_if { |item| item.product == product } end

Generic-user-small
22 Oct 2006, 11:26
Fora User (865 posts)

Or:

  def remove_one(product)
    cart_item = @items.find {|item| item.product == product}
    cart_item.decrement_quantity
    if cart_item.quantity < 1
      remove_all(product)
    end
  end

  def remove_all(product)
    @items.delete_if { |item| item.product == product }
  end
Generic-user-small
22 Oct 2006, 13:10
Fora User (865 posts)
I have been struggling with a screen jump in IE6 when trying out the blinds_down/blinds_up
section of Chapter 9 homework.

The way I read it:
  • The controller returns to the page having put the first item in the cart
  • when loading the page, the call to the hidden_div_if helper method sees an item in the cart and shows the div(not what we want-as we want to invoke blinds down to show it)
  • Then the blinds down call starts its magic, so causing the flicker, or is it just a bug in IE.
Generic-user-small
25 Oct 2006, 17:47
Fora User (865 posts)

I am trying to add orders to the db. The line_items are making it to the line_items table but @orders.save is just passing empty strings to the database and an empty record is created every time. Debug inside the save_orders method shows the @orders object populated as expected, but save just doesn’t pass the values on.

Generic-user-small
25 Oct 2006, 17:47
Fora User (865 posts)

Found the problem, I had to remove…

  attr_reader :name, :address, :email, :pay_type
  attr_writer :name, :address, :email, :pay_type

from order.rb

Generic-user-small
03 Feb 2007, 18:24
Fora User (865 posts)

I tried copying the changes made in depot_l over into my project, and now the “Add to Cart” button for each product has dissappeared.

Anyone run into this?

Generic-user-small
26 Oct 2006, 20:04
Fora User (865 posts)

I was struggling with this myself!

The code in the book is actually correct. The code on the website has several problems.

<%= form_remote_tag :url => { :action => :add_to_cart, :id => product } %> <%= submit_tag “Add to Cart” %> <%= end_form_tag %>

The online code has a “do” in the form_remote_tag call and there is no end_form_tag so their’s no </form> tag.

Brad

Generic-user-small
27 Oct 2006, 01:37
Fora User (865 posts)

Looks like the code didn’t get formatted right in your post, but you lead me down the right path, thanks!

For anyone in the future that runs into this:

<%= form_remote_tag :url => { :action => :add_to_cart, :id => product } %> <%= submit_tag "Add to Cart" %> <%= end_form_tag %>

Generic-user-small
30 Oct 2006, 05:55
Fora User (865 posts)

This started for me after I umcommented config.action_controller.session_store = :active_record_store line in environment.rb (as suggested on page 94).

C:\ruby\projects\depot>ruby script/server => Booting WEBrick…./script/../config/../config/environment.rb:35: undefined method action_controller' for Config:Module (NoMethodError)<br />from ./script/../config/../vendor/rails/railties/lib/initializer.rb:40:in run’
from ./script/../config/../config/environment.rb:13
from c:/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in require'<br /> from ./script/../config/../vendor/rails/activesupport/lib/active_support/dependencies.rb:400:in require’
from ./script/../config/../vendor/rails/railties/lib/commands/servers/webrick.rb:52
from c:/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in require'<br /> from ./script/../config/../vendor/rails/activesupport/lib/active_support/dependencies.rb:400:in require’
from ./script/../config/../vendor/rails/railties/lib/commands/server.rb:39
from c:/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in `require’
from script/server:3

any ideas?

I am currently using the latest EdgeRails revison 5375

Generic-user-small
01 Nov 2006, 12:55
Fora User (865 posts)

It will work a lot better if you use

t.column :price, :decimal, :precision => 8, :scale => 2, :default => 0.00

instead of

t.column :price, :decimal, :percision => 8, :scale => 2, :default => 0.00

my 2 cents…

Generic-user-small
09 Nov 2006, 04:00
Fora User (865 posts)

Working through the “Putting Sessions in the Database” on page 94, creating the 004_add_sessions.rb file works. However, running the rake db:migrate command ALWAYS fails to create the sessions table in mySQL. I’ve done the usual stop/start services, etc. Curiously, if I explicitly state the version to migrate to, the session table is successfully created. In other words, this does NOT work:

rake db:migrate

However, this DOES work:

rake db:migrate VERSION=4

I’ve noticed that migrate seems to be hit or miss on creating other tables as well. Perhaps not so much a comment on the book, but it is a gotcha.

Regards, Carl

Generic-user-small
04 Feb 2007, 17:54
Fora User (865 posts)

Hi All new and old Rails developers.

I hope that somebody can help me with this problem.

I have created everyhting to place an order but my checkout form producers some error in the store controller. When I tryk to place an order I get the following message:

NoMethodError in StoreController#save_order

undefined method `add_line_items_from_cart’ for #

If I comment-out the part of the save order method that adds the line items, it will create an order but with no items just the payment-method selected from the form.

My code is just like the reference one, so I hope that somebody can help me, please!

/Jess

Generic-user-small
13 Nov 2006, 02:53
Fora User (865 posts)

I’m geussing you need to do some sort of itteration in from_cart_item to duplicate the values from the cart_item to the line_item without implicitly specifying variables. I’m not really sure how to code this though so if anyone can give me some tips I sure would appreciate it.

The current code as a reference:

  def self.from_cart_item(cart_item)
    li = self.new
    li.product     = cart_item.product
    li.quantity    = cart_item.quantity
    li.total_price = cart_item.price
    li
  end
Generic-user-small
13 Dec 2006, 03:18
Fora User (865 posts)

After I created static scaffold files (pg. 73) my new and edit product pages don’t work properly. They new page only contain a link back to the list page and the edit page contains a link to the “show” item page and a link to the list page. There is no form to fill in data anymore. I checked the source from the http://media.pragprog.com server and it matches my own for these two pages.

Is this expected? Anyone else notice this?

Mike

Generic-user-small
16 Nov 2006, 01:54
Fora User (865 posts)

Mikeal: In order for your solution to work if Javascript is disabled simply change the [-] to this:

link_to('[-]', :action => :remove_from_cart, :id => cart_item.product)

=]

Generic-user-small
23 Dec 2006, 19:55
Fora User (865 posts)

So the following code as presented in the book doesn’t work with the version of rails that I’m using (not edge):

 <% form_tag do %>

...
    <% end %> 

so i replaced it with:

 <%= form_tag %>

...
    <%= end_form_tag %> 

That seems to have fixed the problem.

Generic-user-small
20 Nov 2006, 19:08
Fora User (865 posts)

thanks, this worked for me, but only after i restarted webrick.

Generic-user-small
22 Jan 2007, 10:33
Fora User (865 posts)

There has already been a post regarding D2. So the button does appear now but it is not working. Having a look at the generated HTML the form tag is missing, there is only a endform tag.

In the BETA PDF (seems to be wrong) is
<% form_remote_tag :url => { :action => :add_to_cart, :id => product } do %> <%= submit_tag “Add to Cart” %> <% end %>

I replaced this with:

<% form_remote_tag :url => { :action => :add_to_cart, :id => product } %> <%= submit_tag “Add to Cart” %> <%= end_form_tag %>

Unfortunately I cannot post HTML Code here, it does not get escaped: in Rails-Terms h(…) is missing!

If I look at the log file I do NOT see any requests to the action add_to_cart! Any idea what could be wrong here?

Many thanks

Tom

Generic-user-small
23 Nov 2006, 22:53
Fora User (865 posts)

I have the same problem…

please help us!!!

Generic-user-small
25 Nov 2006, 12:12
Fora User (865 posts)

I was able to see the call to add_to_cart, but it wouldn’t update the <div id="cart">. This D2 example is really frustrating.

Generic-user-small
29 Nov 2006, 04:08
Fora User (865 posts)

I had the same issue. Basically I started with the form_remote_tag not creating the form tags in html. When I performed the other “d2” fix of using “form_end_tag”, I ended up with your current issue.

I was able to fix it using the original code from the book, but only after updating Rails:

Original code from the book:

<% form_remote_tag :url => { :action => :add_to_cart, :id => product } do %>

<%= submit_tag “Add to Cart” %>

<% end %>

To freeze Rails: at prompt type:

rake:rails:freeze edge

Please pardon the formatting above. I’m not sure how to escape percentage signs yet…

Generic-user-small
29 Nov 2006, 04:13
Fora User (865 posts)

I meant to say that I had to refreeze rails…

Generic-user-small
29 Nov 2006, 07:51
Fora User (865 posts)

I’ve been getting the same error. “ NoMethodError in Store#add_to_cart” “undefined method `title’ for Product:Class”

I think it has something to do with the fact the cart session is not getting created. I doubled checked all my code and compared it bit by bit and it is the same. I am using the version of Rails that included with the book as the final release of 1.2 was not yet available. Anyone else able to get pass this problem? I’m looking forward to continue reading the book but I’m stuck.

Generic-user-small
29 Nov 2006, 08:07
Fora User (865 posts)

Looks like Rails created a session variable as a cookie instead of a DB session, I searched my browsers (firefox) cookie removed the localhost cookie called _session.id and now it works. Wierd

Generic-user-small
29 Nov 2006, 09:57
Fora User (865 posts)

Into Cart creation - Session section “Putting Sessions in the Database” … the rake db:sessions:create (Rake task) doesn’t work. Using RadRails I try to run the task but nothing. Is it required a parameter ? Or can I run simply that task ? Into RadRails: Under depot app … Rake Tasks … db:sessions:create … blank into other parameters field … click on GO button … nothing. the 004_add_sessions.rb not created and next task (db:migrate) of course make an error.

Can you help me ?

Thanks

Carlo

Generic-user-small
13 Dec 2006, 21:01
Fora User (865 posts)

In particular, I often see either

ActiveRecord::StatementInvalid in StoreController#index Mysql::Error: Lost connection to MySQL server during query: SELECT * FROM sessions WHERE (session_id = ‘763685563a12ded01ce4e34a94cf58f1’) LIMIT 1 RAILS_ROOT: C:/railsWork/agileRailsCode/code/depot_r/config/..

or

Status: 500 Internal Server Error Content-Type: text/html Application error (Apache) Change this error message for exceptions thrown outside of an action (like in Dispatcher setups or broken Ruby code) in public/500.html

I’m running the depot_r version on Windows XP using the book’s recommended Instant Rails download. I’m also running edge rails on mongrel. Maybe edge rails is the problem. If so, can anyone point me to a stable version of rails that is still ‘edgy’ enough to allow for rails 1.2 features, like that decimal doo-dad?

Generic-user-small
29 Nov 2006, 17:25
Fora User (865 posts)

http://media.pragprog.com/titles/rails2/code/depot_c/db/migrate/003_add_test_data.rb >”Product.create(:title => ‘Pragmatic Project Automation’, > …… > :price => 29.95)” above is the error place, the price in the database type is integer , so 29.95 can’t insert into the db. you have to change to >”Product.create(:title => ‘Pragmatic Project Automation’, > ……
> :price => 2995)” then “rake db:migrate” will work. in the book it’s right

Generic-user-small
20 Jul 2007, 15:21
Fora User (865 posts)

I followed instructions to build depot application but when I click on Add_to_cart button it shows:
NoMethodError in Store#add_to_cart
Showing app/views/store/add_to_cart.rhtml where line #13 raised:
undefined method `sum’ for # … Array:0x4694994

I tried all solutions:
- I deleted session (by db:session:clear),
- I scanned all code … but it’s all right …

can someone help me ?

Thanks

Generic-user-small
14 Dec 2006, 09:40
Fora User (865 posts)

Firstly, forgive my noobness.

Second, depot iteration F4 isn’t quite working for me, particularly the delete_user action.

I’m not getting any error messages, but clicking on “[X]” to delete any users results in the whole login/list_users page being refreshed, and the webrick output has not mention of “destroy” anywhere.

Any help in getting this working correctly would be greatly appreciated. Thanks.

Generic-user-small
06 Dec 2006, 14:28
Fora User (865 posts)

It seems that reverting to rails 1.16 (I was running that preview for 1.2) fixed my problems so far.

I apologize for taking up bandwidth on the forums.

Generic-user-small
07 Dec 2006, 05:07
Fora User (865 posts)

I followed the book and see fig8.1 undefined method “quantity” and as the author suggests. In Cart.rb and Cart_item.rb , there should be “Include Reloadable” added. But I still see the same error message. Anyone knows another way to make rails recognize the new classes?

Generic-user-small
09 Dec 2006, 14:37
Fora User (865 posts)

Hi Carlo,

I encountered the same problem.

I looked through the Ruby Core API and didn’t find a sum method. :(

I used the following code instead:

def total_price
  @total_price = 0
  @items.each { |item| @total_price + item.price }
  @total_price
end
Generic-user-small
10 Dec 2006, 22:34
Fora User (865 posts)

Thanks guys. I just ran into this same exact problem. I’m using the latest version of InstantRails which is 1.1.something, and the book is using 1.2. Maybe that’s the problem?

Anyway, Christoph’s solution worked, except that the + should be changed to a += or the total price will be $0.00.

Generic-user-small
10 Dec 2006, 22:36
Fora User (865 posts)

Whoops, I formatted that wrong. The plus should be changed to a plusequals.

Generic-user-small
11 Dec 2006, 03:25
Fora User (865 posts)

Thanks for the pointer, this bug drove me nuts (but I found a bunch of great tools).

The symptom that I was seeing involved javascript being returned in a way that replaced the <body> content.

I googled and found suggestions for using “submit_to_remote” but couldn’t get that to work.

Generic-user-small
12 Dec 2006, 06:16
Fora User (865 posts)

I’m still having problems with this one. The first way, it didn’t show the form fields at all. The second way, it shows the form, but it doesn’t write the HTML form tags, so submitting doesn’t do anything. Any pointers?

Generic-user-small
12 Dec 2006, 06:27
Fora User (865 posts)

Never mind. The second version actually works. I forgot to add the = signs.

Generic-user-small
12 Dec 2006, 07:32
Fora User (865 posts)

I think the code to compare the passwords is broken in F1 pg 159 in the 11/22/06 PDF 1.00

I am able to add users with definite mismatched passwords. It looks like the test for user would be false for a new user (no one found in db) and the whole comparison block gets skipped.

Generic-user-small
12 Dec 2006, 20:40
Fora User (865 posts)

Now that’s what I call support! F**X@@@ it.

Generic-user-small
13 Dec 2006, 02:01
Fora User (865 posts)

I noticed this as well, but have not yet discovered the reason.

Generic-user-small
13 Dec 2006, 03:18
Fora User (865 posts)

UPDATE:

I found what was causing the problem for me. In the file models/product.rb, I had added the self.find_products_for_sale method AFTER a protected method.

I’m not entirely sure why that particular method would screw up Edit & New pages, but that fixed the problem for me.

Generic-user-small
13 Dec 2006, 04:49
Fora User (865 posts)

With the correct spelling above I have the same problem. I thought it might be my “mysql” driver, but that appears to be the latest version. I’m using mysql v5…

Generic-user-small
13 Dec 2006, 05:33
Fora User (865 posts)

OKAY You need to be using edge rails to get it to work…change to your application folder and issue the following command:

rake rails:freeze:edge

Generic-user-small
13 Dec 2006, 21:01
Fora User (865 posts)

The first comment is usually an indication that, while you have Ruby and Rails properly installed, you don’t have the MySQL bindings for Rails installed.

From your command line, type “gem install mysql” and choose the MSWin32 version.

Generic-user-small
14 Dec 2006, 09:40
Fora User (865 posts)

I HAVE THE SAME PROBLEM. And I found this link http://books.pragprog.com/titles/rails/errata

And I follow what it suggested. But it has become an compile error. Is it due to some version changes in rails?

Generic-user-small
21 Jan 2007, 00:56
Fora User (865 posts)

While working on getting some Ajax goodness in the Depot app, something went wrong. When I try to load the front page of the catalog, I get a NoMethodError in StoreController#add_to_cart. It’s telling me that I have a nil object where I didn’t expect one, while trying to evaluate nil.product. From looking at it, it seems to me that in the process of switching variables around, specifically setting current_item so the partial can check whether or not we have the current_item (for the Ajax), something isn’t getting set properly. Any hints?

Thanks

Generic-user-small
18 Dec 2006, 12:48
Fora User (865 posts)

If anyone have some input on this issue I’d love to see it! I’m quite stuck at that activity too.

Generic-user-small
23 Dec 2006, 08:42
Fora User (865 posts)

I am using Rails 1.1.6 and when I went to db:migrate on my schema I keep on getting this error (I’m on Windows XP SP2):

== AddPrice: migrating ================================= – add_column(:product, :price, :decimal, (:precision=>8, :scale=>2, :default=>0)) rake aborted! You have a nil object when you didn’t expect it! You might have expected an instance of Array. The error occured while evaluating nil. []

When I was using my Mac I could easily just issues the rake rails:freeze:edge and It was working (of course that was back in october). But my wife broke the mac so now I’m back to sucky ol’ windows. So…back to my question. Do I need to go edge on windows since I’m using the most current Rails of v 1.1.6?

Generic-user-small
23 Dec 2006, 08:42
Fora User (865 posts)

I got rails to edge version and now it all works. It took me a while to realize that I didn’t have the command line version of SVN on my windows machine.

Generic-user-small
23 Dec 2006, 19:55
Fora User (865 posts)

I just want you to know that YOU TOTALLY SAVED MY LIFE with this post!

Thank you for the help..I had the exact same problem when installing acts_as_authenticated and you were the only one on the whole internet that had the answer.

ps-nice site

thanks

John

Generic-user-small
25 Dec 2006, 15:45
Fora User (865 posts)

Now that I’ve got login_controller_test.rb using the users.yml fixture, each method returns a long syntax error regarding the fixture:

Fixture::FormatError: a YAML error occurred parsing /work/depot/config/../test/fixtures/users.yml. Please note that YAML must be consistently indented using spaces. Tabs are not allowed. Please have a look at http://www.yaml.org/faq.html The exact error was:

NameError: uninitialized constant Digest::SHA1 /work/depot/config/../vendor/rails/activerecord/lib/active_record/fixtures.rb:305:in read_fixture_files' /work/depot/config/../vendor/rails/activerecord/lib/active_record/fixtures.rb:279:in initialize’ /work/depot/config/../vendor/rails/activerecord/lib/active_record/fixtures.rb:251:in create_fixtures' /work/depot/config/../vendor/rails/activerecord/lib/active_record/fixtures.rb:250:in create_fixtures’ /work/depot/config/../vendor/rails/activerecord/lib/active_record/base.rb:863:in silence' /work/depot/config/../vendor/rails/activerecord/lib/active_record/fixtures.rb:248:in create_fixtures’ /work/depot/config/../vendor/rails/activerecord/lib/active_record/fixtures.rb:579:in load_fixtures' /work/depot/config/../vendor/rails/activerecord/lib/active_record/fixtures.rb:524:in setup_with_fixtures’ /work/depot/config/../vendor/rails/activerecord/lib/active_record/fixtures.rb:561:in `setup’

I’ve checked over users.yml numerous times, and there really is no problem with the formatting. It was copied directly from http://media.pragprog.com/titles/rails2/code/depot_r/test/fixtures/users.yml.

Any help? (see p. 201 for more information)

Thanks!

  • Brandon
Generic-user-small
27 Dec 2006, 23:57
Fora User (865 posts)

Latest Rails downloaded (v1.2) Using MySQL

The Product validation fails to assert for unqiue title, price nil, price < 0.01 and format of image URL.

Used the downloaded code so I wasn’t making typos. Any ideas? Thanks.

Generic-user-small
17 Jun 2007, 08:16
Fora User (865 posts)

I seem to be having a problem in C2. I’ve arrived at the section labeled “The moral of the story”, but whenever i try and add an item to the cart i get the following error:

h1. NameError in Store#add_to_cart

Showing app/views/store/add_to_cart.rhtml where line #5 raised:

undefined local variable or method `cart_item' for #<#<Class:0x2762310>:0x27622e8>

Extracted source (around line #5):

</code>

then it goes on to list the source from add_to_cart.rhtml , which ive checked and double checked. Ive also checked the rest of the code examples in the chapter and all seems to be correct, any ideas?

Generic-user-small
29 Dec 2006, 02:56
Fora User (865 posts)

All solved :)

Generic-user-small
29 Dec 2006, 21:27
Fora User (865 posts)

I am a bit stuck.

After going through the steps in ch. 8 in the cart creation. I’ve gone through the section 3 times now to check for a typo and my added item, (double checked in /admin dir) isn’t displaying on the store page.

Any help would be GREATLY appreciated, happy coding! :D

Generic-user-small
03 Jan 2007, 00:47
Fora User (865 posts)

When running the migrations, they all work, except that the one which loads data, 003_add_test_data.rb does not load the data. before the environment got messed up, it did work OK. It’s funny, because when we run the app. from the browser, data is entered and stored in the database all right. There is no indication in the log files that anything is amiss. Simply the data isn’t written into the DB. I’m not alone on this issue, see: http://www.ruby-forum.com/topic/92840

Generic-user-small
02 May 2007, 22:19
Fora User (865 posts)

Getting this error while working in Ch. 8/Task C

Showing app/views/store/display_cart.rhtml where line #26 raised:

undefined method `product’ for 15.0:Float

Extracted source (around line #26):

23: </tr> 24: <% 25: for item in @items 26: product = item.product 27: -%> 28: <tr> 29: <td><%= item.quantity %></td>

Generic-user-small
08 Jan 2007, 01:48
Fora User (865 posts)

double post, sorry.

Generic-user-small
08 Jan 2007, 04:48
Fora User (865 posts)

Is this a serious development environment for business applications? I mean, no support for decimal fields sounds pretty limiting to me, but what would i know - i am just a newbie to this environment…

I am having the same trouble with no support for decimal in rake migration and I am looking for the fastest way around this which will still enable me to develop a web e-commerce application (with support for dollars and cents!) when i am done with the tutotials. I am running on Mac and i used the Hivelogic documentation to install Ruby on Rails - it did not install Subversion and since I am the only developer I didnt see any reason to install it. However it appears to be necessary for Edge, and Edge appears to be necessary for support of decimal fields.

Can I resolve this without installing Subversion? And if not, is there an easy installer/doco for Subversion on Mac OS X?

Generic-user-small
08 Jan 2007, 06:51
Fora User (865 posts)

I decided against installing Subversion - i ran the rake rails:freeze:edge command instead and now my decimal field can be added without error. Lets hope decimals are supported in the released version by the time i need to roll out my app… :-)

Generic-user-small
08 Jan 2007, 09:01
Fora User (865 posts)

Showing app/views/admin/checkout.rhtml where line #11 raised:

You have a nil object when you didn’t expect it! You might have expected an instance of Array. The error occured while evaluating nil.include?

Extracted source (around line #11):

*8: <% form_for :list, :url => { :action => :save_list } do |form| %> 9: <p> *10: 皜当腙�讵迂: *11: <%= form.text_field :name, :size => 40 %> 12: </p> *13:

I’m sure added something to the list. It’s not nil. Anyone knows what might go wrong?

THX

Generic-user-small
08 Jan 2007, 22:40
Fora User (865 posts)

I am running on Edge Rails (decimals not supported otherwise) and I am working my way through the tutorial. I have completed the creation of the scaffold code (ruby script/generate scaffold product admin) and accepted the two replacement prompts. However, when I try to view the admin page (http://localhost:3000/admin) I get a screenload of error text:

SyntaxError in AdminController#index

app/models/product.rb:11: parse error, unexpected $, expecting kEND

vendor/rails/activesupport/lib/active_support/dependencies.rb:204:in load_without_new_constant_marking' vendor/rails/activesupport/lib/active_support/dependencies.rb:204:in load_file’ vendor/rails/activesupport/lib/active_support/dependencies.rb:343:in new_constants_in' vendor/rails/activesupport/lib/active_support/dependencies.rb:203:in load_file’ vendor/rails/activesupport/lib/active_support/dependencies.rb:95:in require_or_load' vendor/rails/activesupport/lib/active_support/dependencies.rb:249:in load_missing_constant’ vendor/rails/activesupport/lib/active_support/dependencies.rb:453:in const_missing' vendor/rails/activesupport/lib/active_support/dependencies.rb:465:in const_missing’ vendor/rails/activesupport/lib/active_support/inflector.rb:162:in constantize' vendor/rails/activesupport/lib/active_support/core_ext/string/inflections.rb:148:in constantize’ vendor/rails/actionpack/lib/action_controller/pagination.rb:195:in paginator_and_collection_for' vendor/rails/actionpack/lib/action_controller/pagination.rb:130:in paginate’ app/controllers/admin_controller.rb:12:in list' app/controllers/admin_controller.rb:3:in index’ vendor/rails/actionpack/lib/action_controller/base.rb:1092:in perform_action_without_filters' vendor/rails/actionpack/lib/action_controller/filters.rb:632:in call_filter’ vendor/rails/actionpack/lib/action_controller/filters.rb:634:in call_filter' vendor/rails/actionpack/lib/action_controller/filters.rb:619:in perform_action_without_benchmark’ vendor/rails/actionpack/lib/action_controller/benchmarking.rb:66:in perform_action_without_rescue' /usr/local/lib/ruby/1.8/benchmark.rb:293:in measure’ vendor/rails/actionpack/lib/action_controller/benchmarking.rb:66:in perform_action_without_rescue' vendor/rails/actionpack/lib/action_controller/rescue.rb:115:in perform_action’ vendor/rails/actionpack/lib/action_controller/base.rb:427:in process_without_filters' vendor/rails/actionpack/lib/action_controller/filters.rb:624:in process_without_session_management_support’ vendor/rails/actionpack/lib/action_controller/session_management.rb:114:in process' vendor/rails/actionpack/lib/action_controller/base.rb:330:in process’ vendor/rails/railties/lib/dispatcher.rb:39:in dispatch' vendor/rails/railties/lib/webrick_server.rb:112:in handle_dispatch’ vendor/rails/railties/lib/webrick_server.rb:78:in service' /usr/local/lib/ruby/1.8/webrick/httpserver.rb:104:in service’ /usr/local/lib/ruby/1.8/webrick/httpserver.rb:65:in run' /usr/local/lib/ruby/1.8/webrick/server.rb:173:in start_thread’ /usr/local/lib/ruby/1.8/webrick/server.rb:162:in start_thread' /usr/local/lib/ruby/1.8/webrick/server.rb:95:in start’ /usr/local/lib/ruby/1.8/webrick/server.rb:92:in start' /usr/local/lib/ruby/1.8/webrick/server.rb:23:in start’ /usr/local/lib/ruby/1.8/webrick/server.rb:82:in start' vendor/rails/railties/lib/webrick_server.rb:62:in dispatch’ vendor/rails/railties/lib/commands/servers/webrick.rb:59 /usr/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in require' vendor/rails/activesupport/lib/active_support/dependencies.rb:496:in require’ vendor/rails/activesupport/lib/active_support/dependencies.rb:343:in new_constants_in' vendor/rails/activesupport/lib/active_support/dependencies.rb:496:in require’ vendor/rails/railties/lib/commands/server.rb:39 script/server:3

Not quite what I was expecting…

Any clues?

Generic-user-small
17 Jul 2007, 10:48
Fora User (865 posts)

I’m getting the following error when adding an item to the cart in c3, even after emptying the sessions.

ArgumentError in StoreController#add_to_cart

wrong number of arguments (1 for 0)

any idea?

Generic-user-small
11 Jan 2007, 16:40
Fora User (865 posts)

Hello,

I am trying to save line items from the cart into the database. Running Rails 1.1.6

I get the following error:

bq. ActiveRecord::AssociationTypeMismatch in StoreController#save_order

bq. LineItem expected, got Float

bq. #{RAILS_ROOT}/app/models/order.rb:15:in `add_line_items_from_cart’

bq. #{RAILS_ROOT}/app/models/order.rb:13:in `each’

bq. #{RAILS_ROOT}/app/models/order.rb:13:in `add_line_items_from_cart’

bq. #{RAILS_ROOT}/app/controllers/store_controller.rb:63:in `save_order’

Any guidance would be greatly appreciated. The error occurs when I click Submit Order” It seems to not even check the Order model validation (I can submit blank fields and still get this error).

Thanks,

Adam

Generic-user-small
11 Jan 2007, 16:40
Fora User (865 posts)

Figured it out.

I forgot to return the line item in the self.from_cart_item(cart_item) helper in the line_item.rb model.

neeeded the line:

bq. li

Generic-user-small
04 Sep 2007, 02:38
Fora User (865 posts)

Hi, I’m on Iteration D3 about Highlighting Changes in the cart using AJAX. When I add to the cart, the cart updates, but an error appears in a pop up - ‘RJS Error TypeError $(“current_item) has no properties.

The cart works but the highlight doesn’t happen. Can anyone suggest a fix?

Generic-user-small
21 Jan 2007, 00:53
Fora User (865 posts)

I came across this same error tonight while going through the depot tutorial, and I honestly have no idea how to fix it.

Generic-user-small
21 Jan 2007, 00:56
Fora User (865 posts)

In your store_controller.rb, make sure the definition for the redirect_to_index method is setup to make the message parameter optional:

def redirect_to_index(msg = nil)

Generic-user-small
21 Jan 2007, 01:21
Fora User (865 posts)

I fixed, for me at least. I’d forgotten to add “current_item” outside of the if else statement. I seriously wish the next volume of this book is more consistent with using arrows to indicate changed code, it’s annoying.

Generic-user-small
22 Jan 2007, 10:33
Fora User (865 posts)

I was struggling with this too. But the book’s code is correct. I started with Rails 1.1.6 with the book examples and realize I need Rail 1.2. I’ve upgraded to Rails 1.2 and thought it’s all fine.

However, if I go to the main page (local:3000) to see the environment, it still says the project is with Rails 1.1.6. so what gives?

I then recall somewhere under config/environment.rb, you have to change the line to RAILS_GEM_VERSION = ‘1.2.1’ so it will use the newest version. Then I just restarted everything.

It all makes sense. When you do “rails yourProject”, it uses that version of Rail even if subsequent Rails are updated.

Cheers Happy Railing

Generic-user-small
22 Jan 2007, 12:04
Fora User (865 posts)

in cart.rb

you don’t just add a line “current_item” for it to return that value. You also need to change the else section so if it’s indeed a new item, then current_item is asigned a value

Generic-user-small
25 Jan 2007, 10:36
Fora User (865 posts)

Hi! I’m new to databases, so I’ve got some ‘stupid’ problem and can’t go on with the book. I’m using Locomotive 2.0.8, on Mac Os X 10.3.9. When I open in Terminal the project from Locomotive and try this command:

mysqladmin -u root create depot_development

I get this error:

mysqladmin: command not found

Same thing if I write mysql -u root depot_development.

The config/database yml seems to be ok, with mysql in the adapter fields everywhere, and by default.

Anyone can tell me what’s the matter?

Thank you!

Generic-user-small
22 Jan 2007, 12:46
Fora User (865 posts)

You need to upgrade Rails to 1.2

Remember to edit your environment.rb and change the line RAILS_GEM_VERSION = ‘1.2.0’ (accordingly)

Generic-user-small
22 Jan 2007, 12:47
Fora User (865 posts)

The book’s code is correct if you upgrade your Rail to 1.2

Remember also to update your environment.rb and edit the line to RAILS_GEM_VERSION = ‘1.2.0’

Generic-user-small
22 Jan 2007, 15:38
Fora User (865 posts)

Have you installed mysql database yet?

Generic-user-small
22 Jan 2007, 17:31
Fora User (865 posts)

It should be installed with Locomotive, I think, since the default config/database file has the adapter option setted on mysql by default, when you create a new project.

Generic-user-small
22 Jan 2007, 20:36
Fora User (865 posts)

When I create the store.rhtml file described on 7.2 Add a Page Layout

The banner displays properly

   but   

No dotted line after page title “Your Pragmatic Catalog”

No left side column for Home, Questions, News, Contact links The image is full size The image displays before the title/description Price is not on a separate line No dotted line after product

It looks much like it did before using the store layout except for the banner on top.

I’ve checked public\stylesheets\depot.css, views\store\index.rhtml, views\layouts\store.rhtml and all seems in order.

Is there somewhere I can download these files - I have the book version.

Thanks

Generic-user-small
25 Jan 2007, 10:36
Fora User (865 posts)

Hi,

Locomotive doesn’t include mySql - if you are using the regular (non-server) version of MacOSX you’ll need to install it. Have a quick look back at the chapter about installing, it tells you about sqlite3, which is what Locomotive comes with.

If you want to install mySql it’s relatively painless and Locomotive comes with the drivers you need. If you want to stick with sqlite3, look at the readmes that come with Locomotive and they’ll show you what settings to change. I’ve just been through this and I went with mySql.

Hope this helps, Alastair

Generic-user-small
26 Jan 2007, 00:49
Fora User (865 posts)

Hi,

I ran into the same problem. I had misspelt the method name “initialize” in the CartItem class. Thus, creating a new CartItem:

cart.rb:13 @items « CartItem.new(product)

failed, since the default initialize method doesn’t expect arguments.

Generic-user-small
01 Feb 2007, 06:01
Fora User (865 posts)

I’ve got Ruby 1.8.5 and the latest Rails installed. In the process of debugging I’ve created a unit test to verify that my salable_products method is returning data, and it certainly is. I’ve done everything by the book, verbatim, up to this point, and I’m receiving this error:

NoMethodError in Store#index Showing app/views/store/index.rhtml where line #2 raised:

You have a nil object when you didn’t expect it! You might have expected an instance of Array. The error occurred while evaluating nil.each

Extracted source (around line #2):

1: <table cellpadding="5" cellspacing="0"> 2: <% for product in @products %> 3: <tr valign="top"> 4: <td> 5:

RAILS_ROOT: ./script/../config/..

Application Trace | Framework Trace | Full Trace #{RAILS_ROOT}/app/views/store/index.rhtml:2:in _run_rhtml_47app47views47store47index46rhtml' -e:4:in load’ -e:4 C:/Program Files/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.1/lib/action_view/base.rb:326:in send' C:/Program Files/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.1/lib/action_view/base.rb:326:in compile_and_render_template’ C:/Program Files/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.1/lib/action_view/base.rb:301:in render_template' C:/Program Files/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.1/lib/action_view/base.rb:260:in render_file’ C:/Program Files/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.1/lib/action_controller/base.rb:806:in render_file' C:/Program Files/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.1/lib/action_controller/base.rb:711:in render_with_no_layout’ C:/Program Files/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.1/lib/action_controller/layout.rb:256:in render_without_benchmark' C:/Program Files/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.1/lib/action_controller/benchmarking.rb:50:in render’ C:/Program Files/ruby/lib/ruby/1.8/benchmark.rb:293:in measure' C:/Program Files/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.1/lib/action_controller/benchmarking.rb:50:in render’ C:/Program Files/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.1/lib/action_controller/base.rb:1101:in perform_action_without_filters' C:/Program Files/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.1/lib/action_controller/filters.rb:632:in call_filter’ C:/Program Files/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.1/lib/action_controller/filters.rb:619:in perform_action_without_benchmark' C:/Program Files/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.1/lib/action_controller/benchmarking.rb:66:in perform_action_without_rescue’ C:/Program Files/ruby/lib/ruby/1.8/benchmark.rb:293:in measure' C:/Program Files/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.1/lib/action_controller/benchmarking.rb:66:in perform_action_without_rescue’ C:/Program Files/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.1/lib/action_controller/rescue.rb:83:in perform_action' C:/Program Files/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.1/lib/action_controller/base.rb:430:in send’ C:/Program Files/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.1/lib/action_controller/base.rb:430:in process_without_filters' C:/Program Files/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.1/lib/action_controller/filters.rb:624:in process_without_session_management_support’ C:/Program Files/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.1/lib/action_controller/session_management.rb:114:in process' C:/Program Files/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.1/lib/action_controller/base.rb:330:in process’ C:/Program Files/ruby/lib/ruby/gems/1.8/gems/rails-1.2.1/lib/dispatcher.rb:41:in dispatch' C:/Program Files/ruby/lib/ruby/gems/1.8/gems/rails-1.2.1/lib/webrick_server.rb:113:in handle_dispatch’ C:/Program Files/ruby/lib/ruby/gems/1.8/gems/rails-1.2.1/lib/webrick_server.rb:79:in service' C:/Program Files/ruby/lib/ruby/1.8/webrick/httpserver.rb:104:in service’ C:/Program Files/ruby/lib/ruby/1.8/webrick/httpserver.rb:65:in run' C:/Program Files/ruby/lib/ruby/1.8/webrick/server.rb:173:in start_thread’ C:/Program Files/ruby/lib/ruby/1.8/webrick/server.rb:162:in start' C:/Program Files/ruby/lib/ruby/1.8/webrick/server.rb:162:in start_thread’ C:/Program Files/ruby/lib/ruby/1.8/webrick/server.rb:95:in start' C:/Program Files/ruby/lib/ruby/1.8/webrick/server.rb:92:in each’ C:/Program Files/ruby/lib/ruby/1.8/webrick/server.rb:92:in start' C:/Program Files/ruby/lib/ruby/1.8/webrick/server.rb:23:in start’ C:/Program Files/ruby/lib/ruby/1.8/webrick/server.rb:82:in start' C:/Program Files/ruby/lib/ruby/gems/1.8/gems/rails-1.2.1/lib/webrick_server.rb:63:in dispatch’ C:/Program Files/ruby/lib/ruby/gems/1.8/gems/rails-1.2.1/lib/commands/servers/webrick.rb:59 C:/Program Files/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in gem_original_require' C:/Program Files/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in require’ C:/Program Files/ruby/lib/ruby/gems/1.8/gems/activesupport-1.4.0/lib/active_support/dependencies.rb:496:in require' C:/Program Files/ruby/lib/ruby/gems/1.8/gems/activesupport-1.4.0/lib/active_support/dependencies.rb:343:in new_constants_in’ C:/Program Files/ruby/lib/ruby/gems/1.8/gems/activesupport-1.4.0/lib/active_support/dependencies.rb:496:in require' C:/Program Files/ruby/lib/ruby/gems/1.8/gems/rails-1.2.1/lib/commands/server.rb:39 C:/Program Files/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in gem_original_require’ C:/Program Files/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in require' C:/Program Files/ruby/lib/ruby/gems/1.8/gems/activesupport-1.4.0/lib/active_support/dependencies.rb:496:in require’ C:/Program Files/ruby/lib/ruby/gems/1.8/gems/activesupport-1.4.0/lib/active_support/dependencies.rb:343:in new_constants_in' C:/Program Files/ruby/lib/ruby/gems/1.8/gems/activesupport-1.4.0/lib/active_support/dependencies.rb:496:in require’ script/server:3 #{RAILS_ROOT}/app/views/store/index.rhtml:2:in _run_rhtml_47app47views47store47index46rhtml' C:/Program Files/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.1/lib/action_view/base.rb:326:in send’ C:/Program Files/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.1/lib/action_view/base.rb:326:in compile_and_render_template' C:/Program Files/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.1/lib/action_view/base.rb:301:in render_template’ C:/Program Files/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.1/lib/action_view/base.rb:260:in render_file' C:/Program Files/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.1/lib/action_controller/base.rb:806:in render_file’ C:/Program Files/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.1/lib/action_controller/base.rb:711:in render_with_no_layout' C:/Program Files/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.1/lib/action_controller/layout.rb:256:in render_without_benchmark’ C:/Program Files/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.1/lib/action_controller/benchmarking.rb:50:in render' C:/Program Files/ruby/lib/ruby/1.8/benchmark.rb:293:in measure’ C:/Program Files/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.1/lib/action_controller/benchmarking.rb:50:in render' C:/Program Files/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.1/lib/action_controller/base.rb:1101:in perform_action_without_filters’ C:/Program Files/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.1/lib/action_controller/filters.rb:632:in call_filter' C:/Program Files/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.1/lib/action_controller/filters.rb:619:in perform_action_without_benchmark’ C:/Program Files/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.1/lib/action_controller/benchmarking.rb:66:in perform_action_without_rescue' C:/Program Files/ruby/lib/ruby/1.8/benchmark.rb:293:in measure’ C:/Program Files/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.1/lib/action_controller/benchmarking.rb:66:in perform_action_without_rescue' C:/Program Files/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.1/lib/action_controller/rescue.rb:83:in perform_action’ C:/Program Files/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.1/lib/action_controller/base.rb:430:in send' C:/Program Files/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.1/lib/action_controller/base.rb:430:in process_without_filters’ C:/Program Files/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.1/lib/action_controller/filters.rb:624:in process_without_session_management_support' C:/Program Files/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.1/lib/action_controller/session_management.rb:114:in process’ C:/Program Files/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.1/lib/action_controller/base.rb:330:in process' C:/Program Files/ruby/lib/ruby/gems/1.8/gems/rails-1.2.1/lib/dispatcher.rb:41:in dispatch’ C:/Program Files/ruby/lib/ruby/gems/1.8/gems/rails-1.2.1/lib/webrick_server.rb:113:in handle_dispatch' C:/Program Files/ruby/lib/ruby/gems/1.8/gems/rails-1.2.1/lib/webrick_server.rb:79:in service’ C:/Program Files/ruby/lib/ruby/1.8/webrick/httpserver.rb:104:in service' C:/Program Files/ruby/lib/ruby/1.8/webrick/httpserver.rb:65:in run’ C:/Program Files/ruby/lib/ruby/1.8/webrick/server.rb:173:in start_thread' C:/Program Files/ruby/lib/ruby/1.8/webrick/server.rb:162:in start’ C:/Program Files/ruby/lib/ruby/1.8/webrick/server.rb:162:in start_thread' C:/Program Files/ruby/lib/ruby/1.8/webrick/server.rb:95:in start’ C:/Program Files/ruby/lib/ruby/1.8/webrick/server.rb:92:in each' C:/Program Files/ruby/lib/ruby/1.8/webrick/server.rb:92:in start’ C:/Program Files/ruby/lib/ruby/1.8/webrick/server.rb:23:in start' C:/Program Files/ruby/lib/ruby/1.8/webrick/server.rb:82:in start’ C:/Program Files/ruby/lib/ruby/gems/1.8/gems/rails-1.2.1/lib/webrick_server.rb:63:in dispatch' C:/Program Files/ruby/lib/ruby/gems/1.8/gems/rails-1.2.1/lib/commands/servers/webrick.rb:59 C:/Program Files/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in gem_original_require’ C:/Program Files/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in require' C:/Program Files/ruby/lib/ruby/gems/1.8/gems/activesupport-1.4.0/lib/active_support/dependencies.rb:496:in require’ C:/Program Files/ruby/lib/ruby/gems/1.8/gems/activesupport-1.4.0/lib/active_support/dependencies.rb:343:in new_constants_in' C:/Program Files/ruby/lib/ruby/gems/1.8/gems/activesupport-1.4.0/lib/active_support/dependencies.rb:496:in require’ C:/Program Files/ruby/lib/ruby/gems/1.8/gems/rails-1.2.1/lib/commands/server.rb:39 C:/Program Files/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in gem_original_require' C:/Program Files/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in require’ C:/Program Files/ruby/lib/ruby/gems/1.8/gems/activesupport-1.4.0/lib/active_support/dependencies.rb:496:in require' C:/Program Files/ruby/lib/ruby/gems/1.8/gems/activesupport-1.4.0/lib/active_support/dependencies.rb:343:in new_constants_in’ C:/Program Files/ruby/lib/ruby/gems/1.8/gems/activesupport-1.4.0/lib/active_support/dependencies.rb:496:in require' script/server:3 -e:4:in load’ -e:4 Request Parameters: None

Show session dump


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

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

Generic-user-small
03 Feb 2007, 18:10
Fora User (865 posts)

After adding the “cart” partial inside the “side” div as instructed on pg. 117 ../layouts/store.rhtml

Everything is displayed in the left side bar and the width left for the product discription is onyl about one inch. The cart items are not listed and the product list starts below the links on the left not at the top of the page - this can’t be right.


Total $69.30 —–

Empty Cart

Home</br> FAQ</br> News</br> Contact</br>

Your</br> Pragmatic</br> Catalog</br> </br> …</br> product</br> list</br> …</br> Add To Cart</br>

Generic-user-small
03 Feb 2007, 18:10
Fora User (865 posts)

Typo!!

Generic-user-small
03 Feb 2007, 18:24
Fora User (865 posts)

The code in my book (pg. 119) below doesn’t work at all - the code posted above does. Thanks!!

<%% form_remote_tag :url => { :action => :add_to_cart, :id => product } do %%></br> <%%= submit_tag “Add to Cart” %%></br> <%% end %%>

Generic-user-small
04 Feb 2007, 17:45
Fora User (865 posts)

When I fill out the order form with valid entries for every field all five (5) of the validations below fail. Why aren’t the data being passed from the form to the Order model?

validates_presence_of :name, :address, :email, :pay_type</br> validates_inclusion_of :pay_type, :in => PAYMENT_TYPES.map {|disp,value| value}</br>

Generic-user-small
04 Feb 2007, 17:54
Fora User (865 posts)

Is the method defined in ..\depot\app\models\orders.rb ??

From pg. 141

def add_line_items_from_cart(cart) cart.items.each do |item| li = LineItem.from_cart_item(item) line_items « li end end

Generic-user-small
19 Jul 2007, 12:29
Fora User (865 posts)

When I add either of these to add_to_cart.rjs the orders are not updated until I refresh the screen.

The visual_effects generate a RJS error: [object error]

When they are not present, the orders update as they are supposed to.

page.select(div#notice).each ( |div| div.hide }

page[:current_item].visual_effect :highlight, :startcolor => “#88ff88”, :endcolor => “#114411”

Generic-user-small
06 Feb 2007, 01:34
Fora User (865 posts)

Im getting stuck with decimals too. both commands give me errors.

depot>gem update rails—-include-dependencies and depot>rake rails:freeze:edge

Im using the latest InstantRails on a winxp machine.

Please help!

Generic-user-small
06 Feb 2007, 02:33
Fora User (865 posts)

i got it…nevermind

Generic-user-small
07 Feb 2007, 06:15
Fora User (865 posts)

I’m having the same error that Aswin first mentioned. I’ve checked my code and can’t find any typos, it’s the same as what’s in the book as far as I can tell. I suspect that the source of the problem may be what noahd has stated, but have no idea how to solve it.

Generic-user-small
07 Feb 2007, 18:26
Fora User (865 posts)

in this same example i keep getting this:

NoMethodError in InfoController#who_bought

undefined method `orders’ for #

I have no idea whats going on. I thought i followed the examples in chapter 12 perfectly, but now i keep getting this. i wonder if there is a problem with order versus orders…any help?

Generic-user-small
07 Feb 2007, 18:28
Fora User (865 posts)

In chapter 12, when i attempt to view my xml, i keep getting this error:

NoMethodError in InfoController#who_bought

undefined method `orders’ for #

I have no idea whats going on. I thought i followed the examples in chapter 12 perfectly, but now i keep getting this. i wonder if there is a problem with order versus orders…any help?

Generic-user-small
01 Aug 2007, 21:35
Fora User (865 posts)

I have an error with the following part: post_via_redirect “/store/save_order”, :order => { :name => “Dave Thomas”, :address => “123 The Street”, :email => “dave@pragprog.com”, :payment_type_id => “check” } assert_response :success assert_template “index” assert_equal 0, session[:cart].items.size

assert_template returns “checkout” instead of “index”. I tried changing assert_template to “checkout” just to verify the assert_equal, and it was equal to 1 instead of 0. In short, I think the test does not pass through the save_order process correctly - but my actual application works perfectly and orders are added to the database. Does anybody have an idea of the problem? Thanks a lot!

Generic-user-small
07 Feb 2007, 22:27
Fora User (865 posts)

one suggestion from me would be to clear your cache and cookies. i have had to do this countless times during the writing of this program and generally things start identifying after i do it.

just an idea

Generic-user-small
09 Feb 2007, 05:45
Fora User (865 posts)

Well, I’ve resorted to using the online code from the website and the error’s gone, it was probably a typo of mine but I don’t know what.

…just tying up lose ends for anyone else who reads this–the online code at least solved my problem.

Generic-user-small
12 Feb 2007, 17:39
Fora User (865 posts)

i’ve the same problem, did you solve it?

Generic-user-small
13 Feb 2007, 15:10
Fora User (865 posts)

I’ve met the same problem can anyone help me solve this?

Generic-user-small
15 Feb 2007, 20:26
Fora User (865 posts)

To be more specific, the else section should look as follows:

current_item = CartItem.new(product)
@items « current_item

Generic-user-small
15 Feb 2007, 20:42
Fora User (865 posts)

I had the same problems but found the solution…

def find_cart session[@cart] ||= Cart.new end

(note the use of @cart instead of :cart)

On the errata pages for this book…

http://books.pragprog.com/titles/rails/errata

Generic-user-small
10 Jul 2007, 15:24
Fora User (865 posts)

I downloaded the code from the book’s website and pasted it into 003_add_test_data.rb. I saved it and then did a “rake db:migrate”. Under my impression from what the book is telling me, that should populate the database with 3 rows, but it doesn’t seem to be doing anything to the database at all. I’ve got 1 record in there that I added before, and that record is still there. What might I be doing wrong? Here is the code:

class AddTestData < ActiveRecord::Migration
  def self.up
		Product.create(:title => 'Pragmatic Project Automation',
    :description => 
    %{<p>
       <em>Pragmatic Project Automation</em> shows you how to improve the 
       consistency and repeatability of your project's procedures using 
       automation to reduce risk and errors.
      </p>
      <p>
        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.
      </p>},
    :image_url =>   '/images/auto.jpg',    
    :price => 29.95)


    Product.create(:title => 'Pragmatic Version Control',
      :description =>
      %{<p>
         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.
      </p>},
    :image_url => '/images/svn.jpg',
    :price => 28.50)


    Product.create(:title => 'Pragmatic Unit Testing (C#)',
    :description => 
    %{<p>
        Pragmatic programmers use feedback to drive their development and 
        personal processes. The most valuable feedback you can get while 
        coding comes from unit testing.
      </p>
      <p>
        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.
      </p>},
    :image_url => '/images/utc.jpg',
    :price => 27.75)

  end

  def self.down
		Product.delete_all
  end
end
Generic-user-small
20 Feb 2007, 15:40
Fora User (865 posts)

Basically, this same problem has been posted before, but I get the following error when I run rake db:migrate.

rake aborted! ./db/migrate//003_add_test_data.rb:1: formal argument cannot be a constant version control: it’ng quickly—and correctly. All projects needl ^ ./db/migrate//003_add_test_data.rb:1: parse error, unexpected ‘.’, expecting ‘\n’ or ‘;’ version control: it’ng quickly—and correctly. All projects needl

Is something wrong with the online code at http://media.pragprog.com/titles/rails2/code/depot_c/db/migrate/003_add_test_data.rb

Generic-user-small
22 Feb 2007, 20:34
Fora User (865 posts)

I was also getting the same error.

I upgraded to the latest version gem install mysql and installed the latest window version 2.7.3 and now I get a dialog box titled “ruby.exe - Entry Point Not Found” And the contents reads: “The procedure entry point mysql_stmt_row_tell could not be located in the dynamic link library LIBMYSQL.dll”

Has anyone struck this??

Generic-user-small
24 Feb 2007, 22:27
Fora User (865 posts)

I am following the depot application. I am using windows nt and mysql. I have created the controller. I then went to create the maintenance app. I put “scaffold :product” within the AdminController class. Restarted the server. No “view” pages have been created. As expected error in browser:

“no route found to match “/admin/new” with {:method=>:get}”

The browser image on page 68 also should also be pointed to depot/admin

I think there is step missing of building the scaffold using the command prompt. The view pages are not being built

Generic-user-small
24 Feb 2007, 22:27
Fora User (865 posts)

My mistakes:

I deleted the database and recreated, restarted the server,remigrated the db. It is working, though without seeing files in the view…will have to read on for answer.

Also the /admin is correct. For each project you cd into the new project and that becomes the root.

Anyway enjoying reading tbe book.

Generic-user-small
22 Mar 2007, 19:05
Fora User (865 posts)

Hello, please advice what should i do to place currency unit on the other side from numbers? I live in Russia, and we usualy place units after digits, like “price is 100 roubles” thanks!

Generic-user-small
02 Mar 2007, 07:36
Fora User (865 posts)

I have followed the instructions exactly, but i can’t get alternating backgrounds to work in Iteration A4. Is this a limitation of IE7?

Thanks,

Generic-user-small
27 Feb 2007, 11:25
Fora User (865 posts)

Hi! I’m studying version 2, (200-11-22). I’ve got a problem on page 157: I can register new users, but when I then try to login, the app always says that I’m entering an ‘invalid user/password combination’. Anyone knows the problem?

Thank you!

Generic-user-small
27 Feb 2007, 11:21
Fora User (865 posts)

ok, I’ve found the problem:

in user.rb

I must return the user at the end of the authenticate method. This is not written in the book, but i’ve found it in the downlodable code.

Generic-user-small
27 Feb 2007, 11:25
Fora User (865 posts)

… It’s written on the book on page 150… Sorry…

Generic-user-small
28 Feb 2007, 00:59
Fora User (865 posts)

I guess i didn’t provide enough details. I figured it out. I missed the <div id="product-list"> </div> tags.

Generic-user-small
02 Mar 2007, 07:36
Fora User (865 posts)

Stripes didn’t work for me at first either- here’s why….

pg 89; the online file “Download depot_b/app/views/layouts/admin.rhtml” omits part of a line which text asks readers to include.

Online version: <%= stylesheet_link_tag ‘scaffold’ %> “ Text version: <%= stylesheet_link_tag ‘scaffold’ , ‘depot’ %>

Generic-user-small
14 Mar 2007, 05:08
Fora User (865 posts)

Hi,

I’m up to page 195 in the book. I get an error in @test_index_with_user@, it looks like the session id is not getting set, so the server redirects to the login page:

C:\rails\depot> ruby test\functional\login_controller_test.rb Loaded suite test/functional/login_controller_test Started .F.. Finished in 0.45 seconds.

1) Failure: test_index_with_user(LoginControllerTest) [c:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.2/lib/action_controller/assertions/response_assertions.rb:26:in assert_response' c:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.2/lib/action_controller/assertions/response_assertions.rb:18:in assert_response’ test/functional/login_controller_test.rb:41:in `test_index_with_user’]: Expected response to be a , but was <302>

4 tests, 8 assertions, 1 failures, 0 errors Process ruby exited with code 1

Looks like the user_id isn’t getting set here:

def test_index_with_user get :index, {}, { :user_id => users(:dave).id } assert_response :success assert_template “index” end

The test.log file shows:

The SQL statement seems to indicate that users.id is not getting set???

Here’s what’s in my users.yml:

<%% SALT = “NaCl” unless defined?(SALT) %%>

dave: id: 1 name: dave salt: <%%= SALT %%> hashed_password: <%%= User.encrypted_password(‘secret’, SALT) %%>

So I’m stumped!

Thanks

P

Generic-user-small
02 Mar 2007, 11:08
Fora User (865 posts)

Hi, I have the same problem. I added the assertion:

assert_equal 1, users(:dave).id

Its OK while this fails:

assert_equal 1, session[:user_id]

So the problem seems to be with setting the session variable, user.id seems to be correctly set.

I am still using file based sessions not database as described in the book. Maybe file based sessions don’t work with the test framework?

Roger

Generic-user-small
02 Mar 2007, 22:19
Fora User (865 posts)

After spending some time with Google I found this:

http://manuals.rubyonrails.com/read/chapter/28

So I followed the example there and changed the first line to:

get :index, {}, { ‘user_id’ => users(:dave).id }

And its working!

Should this be reported as an erratum or am I missing something? Seems a bit odd that it hasn’t been discovered before….

Generic-user-small
03 Mar 2007, 01:51
Fora User (865 posts)

I’m having the same problem. Mind sharing your solution?

Generic-user-small
22 Jun 2007, 02:12
Fora User (865 posts)

Can’t get the correct error, “undefined method ‘product’…”

Instead, when adding item to my cart after completing section C2, I get the following error:

NoMethodError in Store#add_to_cart Showing app/views/store/add_to_cart.rhtml where line #5 raised:

undefined method `quantity’ for #

Extracted source (around line #5):

    <% for cart_item in @cart.items %>
  • <%= cart_item.quantity %> × <%= h(cart_item.title) %>
  • <% end %>
Generic-user-small
03 Mar 2007, 03:55
Fora User (865 posts)

Solved:

pg 104-106, Chptr 8.1 Refer to “Putting Sessions in the Database”

rake db: sessions: create rake db: migrate

in config/environment.rb, enable last line (below) by removing # sign:

Use the database for sessions instead of the file system

# (create the session table with ‘rake db:sessions:create’) # config.action_controller.session_store = :active_record_store

Generic-user-small
03 Mar 2007, 23:28
Fora User (865 posts)

I had the same error as roger. changing :user_id to ‘user_id’ also worked for me.

ruby -v gives me: 1.8.5 (2006-12-25 patchlevel 12) [i386-mswin32]

rails -v gives me: 1.2.2

Can anyone confirm if this is a version issue? If so, is it a ruby version issue or a rails version issue?

Thanks

Generic-user-small
04 Mar 2007, 21:53
Fora User (865 posts)

Hi Roger,

Your fix worked for me too, thanks for finding that!

I couldn’t figure out how the “get” method works from reviewing the Rails API documentation, nor do I yet understand the difference between :user_id (a symbol?) and ‘user_id’ (a literal string) as it is used with the get method. Have you found anything that would be enlightening, either online, or in AWDWR or Programming Ruby?

phylae, I am running the following environment:

C:\rails\depot>rails -v
Rails 1.2.2

C:\rails\depot>ruby -v
ruby 1.8.5 (2006-08-25) [i386-mswin32]

Doesn’t appear to be significantly different than yours.

P

Generic-user-small
04 Mar 2007, 22:12
Fora User (865 posts)

I’ve also posted this to the AWDWR errata page http://books.pragprog.com/titles/rails2/errata

P

Generic-user-small
05 Mar 2007, 17:48
Fora User (865 posts)

I am following instructions step by step - on page 97 I ran rake db:create:sessions and this seems to have correctly created my 004_add_sessions.rb file.

However, when I run rake db:migrate, it leaves me at version 3 and I don’t know how to debug this. My schema table shows I am still at version 3.

Does anyone know how to see what’s going wrong and why my 004_add_sessions.rb is not executing ?

Thanks!

Generic-user-small
06 Mar 2007, 15:07
Fora User (865 posts)

I am following instructions step by step - on page 97 I ran rake db:create:sessions and this seems to have correctly created my 004_add_sessions.rb file.

However, when I run rake db:migrate, it leaves me at version 3 and I don’t know how to debug this. My schema table shows I am still at version 3.

Does anyone know how to see what’s going wrong and why my 004_add_sessions.rb is not executing ?

Thanks!

Generic-user-small
06 Mar 2007, 06:25
Fora User (865 posts)

Hi, are you seeing any messages when you run db:migrate?

RogEr

Generic-user-small
06 Mar 2007, 15:02
Fora User (865 posts)

Hi - thanks for answering.

I ran db:migrate –trace inside radrails/eclipse.

When I run it from a command window, the window disappears - as if it hit some error and killed the window.

Insite eclipse, the console show the following messages.

C:0:Warning: require_gem is obsolete. Use gem instead. C:0:Warning: require_gem is obsolete. Use gem instead. (in C:/InstantRails/rails_apps/Depot) ** Invoke db:migrate (first_time) ** Invoke environment (first_time) ** Execute environment ** Execute db:migrate ** Invoke db:schema:dump (first_time) ** Invoke environment ** Execute db:schema:dump


The development.log file shows these messages:

SQL (0.000000) Mysql::Error: #42S01Table ‘schema_info’ already exists: CREATE TABLE schema_info (version int(11)) SQL (0.000000) SELECT version FROM schema_info SQL (0.000000) SELECT version FROM schema_info SQL (0.000000) SELECT version FROM schema_info SQL (0.000000) SELECT * FROM schema_info SQL (0.000000) SHOW TABLES SQL (0.000000) SHOW FIELDS FROM products SQL (0.000000) SHOW KEYS FROM products


The schema table shows that I am at version 3, even though my last migrate task is: 004_add_sessions.

That file was created by running rake db:sessions:create and it contains:

class AddSessions < ActiveRecord::Migration def self.up create_table :sessions do |t| t.column :session_id, :string t.column :data, :text t.column :updated_at, :datetime end

add_index :sessions, :session_id
add_index :sessions, :updated_at   end

def self.down drop_table :sessions end end


Any idea of how to debug this?

Thanks, Kurt

Generic-user-small
06 Mar 2007, 15:04
Fora User (865 posts)

Correction - that source file looks a lot better than it appears in the above post:

class AddSessions < ActiveRecord::Migration def self.up create_table :sessions do |t| t.column :session_id, :string t.column :data, :text t.column :updated_at, :datetime end

add_index :sessions, :session_id
add_index :sessions, :updated_at   end

def self.down drop_table :sessions end end

Generic-user-small
06 Mar 2007, 15:06
Fora User (865 posts)

ok, trying again for good formatting:

class AddSessions < ActiveRecord::Migration def self.up create_table :sessions do |t| t.column :session_id, :string t.column :data, :text t.column :updated_at, :datetime end

add_index :sessions, :session_id
add_index :sessions, :updated_at   end

def self.down drop_table :sessions end end

Generic-user-small
06 Mar 2007, 15:07
Fora User (865 posts)

well, it won’t format correctly. but the source file looks good to me. thank you.

Generic-user-small
07 Mar 2007, 07:20
Fora User (865 posts)

I’ve been working through the book on both a PC and a Mac.

Oddly enough, the PC wants a string “user_id”, and the Mac wants the symbol :user_id.

Phipster has a “c:" in his posts, and Phylae has “mswin32”, so that leaves Roger.

So Roger, did I guess correctly? Are you also on Windows?

I haven’t tried it on Linux yet…

-Brandon

Generic-user-small
08 Mar 2007, 00:53
Fora User (865 posts)

I’m running InstantRails version 1.4 and have encountered the same problem.

No Method Error in Store#add_to_cart undefined method `sum’ Extracted source (around line #13):

<%= number_to_currency(@cart.total_price) %></td>

Generic-user-small
08 Mar 2007, 23:40
Fora User (865 posts)

OS X, 10.4.8, built from scratch

Rails 1.2.2 ruby 1.8.5 (2006-12-25 patchlevel 12) [powerpc-darwin8.8.0]

I had to change it to ‘user_id’ to make it work.

SO GLAD I found the original mention in the errata - THANK YOU!

Generic-user-small
10 Mar 2007, 03:24
Fora User (865 posts)

any help would be great, never figured this problem out.

Generic-user-small
18 Jul 2007, 18:55
Fora User (865 posts)

I am having a problem with the ajax version of the add to cart. When I click on the “Add to Cart” button of the ajax version, the post to the server works because the data is added to the session database but the page is not updated with the new cart item. If I hit refresh on Firefox then I see the item I added to the cart. I don’t see any errors in the log files. Below is the code I have in the add_to_cart.rjs

page.replace_html(“cart”, :partial => “cart”, :object => @cart)

Generic-user-small
13 Mar 2007, 08:14
Fora User (865 posts)

I’m stuck on page 162. The “Enter User Details” page draws up fine, but when I “add user”, this is brought up: ** NoMethodError in LoginController#add_user

undefined method `hashed_password=’ for #

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

C:/InstantRails-1.6-win/InstantRails/ruby/lib/ruby/gems/1.8/gems/activerecord-1.15.2/lib/active_record/base.rb:1858:in method_missing' #{RAILS_ROOT}/app/models/user.rb:40:in password=’ #{RAILS_ROOT}/app/controllers/login_controller.rb:38:in new' #{RAILS_ROOT}/app/controllers/login_controller.rb:38:in add_user’

Request

Parameters: {“user”=>{“name”=>”dole”, “password_confirmation”=>”dole”, “password”=>”dole”}, “commit”=>”Add User”}

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


I’ve replaced all my files with ones provided, still the same error. I’ve tried updating mySQL as suggested in http://fora.pragprog.com/agile-web-development-with-rails-2nd-ed/the-depot-application/post/719, but that did not fix the problem either. This is rather frustrating, as the main focus I’m learning rails is for a user content site. Adding users would be useful! ;)

Any help?

Generic-user-small
12 Mar 2007, 01:40
Fora User (865 posts)

I had a similar problem, but I restarted all the servers, cleared the sessions, and then everything seemed to work.

Generic-user-small
12 Mar 2007, 01:44
Fora User (865 posts)

Glenn I’ve got the exact same problem.

Generic-user-small
12 Mar 2007, 16:49
Fora User (865 posts)

I was following the example and run into an error message with Iteration A2. Please help! The error message is as follow:-

Thanks a lot!

C:\InstantRails\rails_apps\depot>rake db:migrate (in C:/InstantRails/rails_apps/depot) == AddPrice: migrating ======================================================== – add_column(:products, :price, :decimal, {:precision=>8, :scale=>2, :default=> 0}) rake aborted! You have a nil object when you didn’t expect it! You might have expected an instance of Array. The error occured while evaluating nil.[]

(See full trace by running task with –trace)

Generic-user-small
13 Mar 2007, 08:13
Fora User (865 posts)

Okay, figured out everything (or so I hope).

For the undefined method, make sure that in your database, that there is a row for ‘password’ and that its not misspelled or anything.

And as for the Mysql crap, I’m using instantrails, so what I did was I deleted the whole damned thing (after backing up my depot app), and then reinstalled instantrails, copied the Depot folder back in, created the depot_development table, then migrated. Works like a jiffy now.

Generic-user-small
13 Mar 2007, 08:14
Fora User (865 posts)

Solved. I had misspelled ‘hashed’ by accident, and the mysql table was messed up. Cleaned that up and all works.

Generic-user-small
14 Mar 2007, 01:59
Fora User (865 posts)

Ok, so I can’t just let this go for some reason. I threw a breakpoint into the authorize method in the ApplicationController class (just before the unless User.find_by…method). In irb I typed session to get a listing of the contents of session and got what you see below. I know that the [](string) method for this session object is accessing @attributes as it should be because typing session[:flash] returns {} however session[:user_id] returns nil. Ideas?

#<ActionController::TestSession:0x25215e0 \
@saved_attributes=nil, @attributes={:user_id=>1, "flash"=>{}}, @session_id="">
Generic-user-small
14 Mar 2007, 02:41
Fora User (865 posts)

Ok, I now know why this isn’t working (why can’t I just let these things go?)

I looked at the ActionController::TestSession (if you trace the get method you will be lead back to this class). I pasted the code from my version of this class below for reference (from actionpack-1.13.2). You can see that initialize just assigns it’s attributes parameter to an instance variable. I will save you some tracing and tell you that the third argument to get is passed (eventually) to a new instance of TestSession. Since TestSession’s [](key) method returns data[key.to_s] instead of data[key] session[:user_id] will work if (and only if) session.data (session’s @attributes instance variable for all intents and purposes) contains the key :user_id.to_s (‘user_id’). Maybe I should submit a patch ;).

Hope this helps…

 class TestSession #:nodoc:
    attr_accessor :session_id
def initialize(attributes = nil)
  @session_id = ''
  @attributes = attributes
  @saved_attributes = nil
end

def data
  @attributes ||= @saved_attributes || {}
end

def [](key)
  data[key.to_s]
end

def []=(key, value)
  data[key.to_s] = value
end

def update
  @saved_attributes = @attributes
end

def delete
  @attributes = nil
end

def close
  update
  delete
end   end
Generic-user-small
14 Mar 2007, 03:25
Fora User (865 posts)

Ok, mystery solved…check out http://dev.rubyonrails.org/ticket/7372 (the RoR bug tracking database) for a more in-depth description of the problem. To summarize, this is a bug that was introduced with Rails 1.2.2 and fixed in 1.2.3 so upgrade to 1.2.3 and test should all pass.

Generic-user-small
14 Mar 2007, 05:08
Fora User (865 posts)

Brilliant sleuthing, Ross! Thanks for all your hard work.

Generic-user-small
14 Mar 2007, 22:05
Fora User (865 posts)

The example code in the download is correct. I still needed to see the comment here so that I knew which file to look at, though. Sigh.

Generic-user-small
18 Mar 2007, 09:34
Fora User (865 posts)

Hi, in Task G, Another Way of Requesting XML section. He said ‘routes.rb’ should change to this:

ActionController::Routing::Routes.draw do |map| map.connect ‘:controller/service.wsdl’ , :action => ‘wsdl’ map.connect ‘:controller/:action/:id’ map.connect ‘:controller/:action/:id.:format’ end

But map.connect ‘:controller/:action/:id.:format’ does not work. No matter what I ask for /info/who_bought/1.html or /info/who_bought/1.xml, I got the html format.

I found it depends on the order declared in ‘respond_to’

def who_bought @product = Product.find(params[:id]) @orders = @product.orders respond_to do |format| format.html format.xml end end

If I change the order to:

respond_to do |format| format.xml format.html end

I got the xml response but never html response.

I thought the map.connect ‘:controller/:action/:id.:format’ does not work here. But why? How to fix this?

Thank you.

Generic-user-small
23 Mar 2007, 12:33
Fora User (865 posts)

in Depot Iteration A4 we use the 003_add_test.rb test data. The file in the book and the file online are different. But what’s worse, both contain HTML elements, but when inserted into the Depot app, the HTML elements are escaped and thus appear in the app almost like code or a pre element were used! What gives? How can we turn on or turn off this escaping feature when running test data?

Generic-user-small
22 Mar 2007, 19:05
Fora User (865 posts)

I was wondering too. I sent a patch to the developers http://dev.rubyonrails.org/ticket/7892 It’s my first one and very easy.

Как книжка? По мне так просто класс!

Generic-user-small
23 Mar 2007, 12:33
Fora User (865 posts)

Answer to my own question is on p.82 of 2nd Edition. I was mystified because scaffold generates this stuff on-the-fly, and I didn’t know what it contained!

Generic-user-small
24 Mar 2007, 04:09
Fora User (865 posts)

I’m following along in the book to create the depot application. I’m having an issue with the form fields not appearing after creating the adminController on page 67. Its like its not recognizing my 001_create_products.rb. After clicking the submit button it creates a new row. But none of the fields that I created in the migrate file are created in the table.

Can any one point me in the right direction to getting this working?

BTW, I’ve just reinstalled all of the apps recommended on the HiveLogic.

http://hivelogic.com/narrative/articles/ruby-rails-mongrel-mysql-osx

Thanks,

William

Generic-user-small
24 Mar 2007, 04:09
Fora User (865 posts)

Please disregard this post. I made really goofy mistake.

Generic-user-small
03 Apr 2007, 14:28
Fora User (865 posts)

I am using the PDF book. On section 6.4 Iteration A4: Prettier Listing I am having some problems. i did the first command: ruby script/generate scaffold products admin after than i did this: ruby script/generate migration add_test_data and it creates a file on db/migrate/003_add_test_data.rb ater editing than on with the code below it i get this error:

$/var/www/depot$ sudo rake db:migrate –trace (in /var/www/depot) ** Invoke db:migrate (first_time) ** Invoke environment (first_time) ** Execute environment ** Execute db:migrate == AddTestData: migrating ===================================================== rake aborted! /var/www/depot/config/../app/models/product.rb:12: syntax error, unexpected $end, expecting kEND /usr/lib/ruby/gems/1.8/gems/activesupport-1.4.1/lib/active_support/dependencies.rb:203:in load_without_new_constant_marking' /usr/lib/ruby/gems/1.8/gems/activesupport-1.4.1/lib/active_support/dependencies.rb:203:in load_file’ /usr/lib/ruby/gems/1.8/gems/activesupport-1.4.1/lib/active_support/dependencies.rb:342:in new_constants_in' /usr/lib/ruby/gems/1.8/gems/activesupport-1.4.1/lib/active_support/dependencies.rb:202:in load_file’ /usr/lib/ruby/gems/1.8/gems/activesupport-1.4.1/lib/active_support/dependencies.rb:94:in require_or_load' /usr/lib/ruby/gems/1.8/gems/activesupport-1.4.1/lib/active_support/dependencies.rb:248:in load_missing_constant’ /usr/lib/ruby/gems/1.8/gems/activesupport-1.4.1/lib/active_support/dependencies.rb:452:in const_missing' /usr/lib/ruby/gems/1.8/gems/activesupport-1.4.1/lib/active_support/dependencies.rb:464:in const_missing’ /usr/lib/ruby/gems/1.8/gems/activesupport-1.4.1/lib/active_support/dependencies.rb:260:in load_missing_constant' /usr/lib/ruby/gems/1.8/gems/activesupport-1.4.1/lib/active_support/dependencies.rb:468:in const_missing’ ./db/migrate//003_add_test_data.rb:9:in real_up' /usr/lib/ruby/gems/1.8/gems/activerecord-1.15.2/lib/active_record/migration.rb:212:in migrate’ /usr/lib/ruby/1.8/benchmark.rb:293:in measure' /usr/lib/ruby/gems/1.8/gems/activerecord-1.15.2/lib/active_record/migration.rb:212:in migrate’ /usr/lib/ruby/gems/1.8/gems/activerecord-1.15.2/lib/active_record/migration.rb:335:in migrate' /usr/lib/ruby/gems/1.8/gems/activerecord-1.15.2/lib/active_record/migration.rb:330:in migrate’ /usr/lib/ruby/gems/1.8/gems/activerecord-1.15.2/lib/active_record/migration.rb:297:in up' /usr/lib/ruby/gems/1.8/gems/activerecord-1.15.2/lib/active_record/migration.rb:288:in migrate’ /usr/lib/ruby/gems/1.8/gems/rails-1.2.2/lib/tasks/databases.rake:4 /usr/lib/ruby/gems/1.8/gems/rake-0.7.2/lib/rake.rb:399:in execute' /usr/lib/ruby/gems/1.8/gems/rake-0.7.2/lib/rake.rb:399:in execute’ /usr/lib/ruby/gems/1.8/gems/rake-0.7.2/lib/rake.rb:369:in invoke' /usr/lib/ruby/1.8/thread.rb:135:in synchronize’ /usr/lib/ruby/gems/1.8/gems/rake-0.7.2/lib/rake.rb:362:in invoke' /usr/lib/ruby/gems/1.8/gems/rake-0.7.2/lib/rake.rb:1935:in run’ /usr/lib/ruby/gems/1.8/gems/rake-0.7.2/lib/rake.rb:1935:in `run’ /usr/lib/ruby/gems/1.8/gems/rake-0.7.2/bin/rake:7 /usr/bin/rake:16

Generic-user-small
07 Apr 2007, 05:43
Fora User (865 posts)

On pages 114-118 (of the PDF at least) we’re led though Exception handling which elegantly (or our application I suppose) recovers from a non-existent product ID.

While the method works as advertised for bad entries like [http://localhost:3000/store/add_to_cart/foo] there is a significant flaw if an integer precedes our string: eg [http://localhost:3000/store/add_to_cart/2foo] – in this case it actually adds item #2 to our cart!

Anyone have a fix for this bug?

Cheers, Mat

Generic-user-small
09 Apr 2007, 17:57
Fora User (865 posts)

That’s because the book doesn’t yet tell you to change the field type to FLOAT from INTEGER. The migrate trys to add decimal values to field type INTEGER in MySQL.

How to fix:

Edit your db/migrate/002_add_price.rb

Change:

add_column :products, :price, :integer, :default => 0

To:

add_column :products, :price, :float, :default => 0

Now you must change your validation rules in your models/product.rb

Change:

validates_numericality_of :price, :only_integer => true

To:

validates_numericality_of :price, :only_float => true

Roll back your database to before that and then update your database again:

rake db:migrate VERSION=1 rake db:migrate

003_add_test_data should now have executed as it should and you will find you have the 3 products in your database!

Generic-user-small
09 Apr 2007, 19:38
Fora User (865 posts)

I’ve fixed the above the wrong way! It seems that further in the book the data type is expected to be INTEGER. Therefore, instead of changing the migrate and the model you should change the 003_add_test_data by taking the decimal points out.

Generic-user-small
01 May 2007, 18:13
Fora User (865 posts)

Help, i am stuck on chapter 11. When I try to view the add_user page I get the following error:

Mysql::Error: Table ‘depot_development.users’ doesn’t exist: SHOW FIELDS FROM users

/usr/local/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/connection_adapters/abstract_adapter.rb:128:in log' /usr/local/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/connection_adapters/mysql_adapter.rb:243:in execute’ /usr/local/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/connection_adapters/mysql_adapter.rb:348:in columns' /usr/local/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/base.rb:763:in columns’ /usr/local/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/base.rb:2060:in attributes_from_column_definition_without_lock' /usr/local/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/locking/optimistic.rb:45:in attributes_from_column_definition’ /usr/local/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/base.rb:1502:in initialize_without_callbacks' /usr/local/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/callbacks.rb:225:in initialize’ app/controllers/login_controller.rb:5:in new' app/controllers/login_controller.rb:5:in add_user’

I have looked everywhere online and cant find a reason why this is happening. I also downloaded the code from the website and I get the same error when I try to use the depot_p code. Anyone else have this problem?

Richard

Generic-user-small
22 Jun 2007, 01:57
Fora User (865 posts)

When I do migrate, a DDL statement gives an error 42S01. It’s supposed to just alter the table, but the MySQL output indicates it’s trying to create a table line_items instead, which has just been created earlier. Does anyone know why so? I’m using MySQL 5.0.37. Thanks.

006_create_line_items.rb

create_table :line_items do |t . . . execute “alter table line_items add constraint fk_line_item_products foreign key (product_id) references products(id)”

execute "alter table line_items add constraint fk_line_item_orders
           foreign key  (order_id) references orders(id)" . . .

D:\Rails Projects\Depot>rake db:migrate (in D:/Rails Projects/Depot) == CreateOrders: migrating ==================================================== – create_table(:orders) -> 0.1500s == CreateOrders: migrated (0.1500s) ===========================================

== CreateLineItems: migrating ================================================= – create_table(:line_items) rake aborted! Mysql::Error: #42S01Table ‘line_items’ already exists: CREATE TABLE line_items ( id int(11) DEFAULT NULL auto_increment PRIMARY KEY, product_id int(11) NOT N ULL, order_id int(11) NOT NULL, quantity int(11) NOT NULL, total_price dec imal(8,2) NOT NULL) ENGINE=InnoDB

Generic-user-small
10 Apr 2007, 13:31
Fora User (865 posts)

Solved…

Generic-user-small
27 May 2007, 19:15
Fora User (865 posts)

Hi, I used your link to the MacPorts installations by James Duncan Davidson. I’m on an intel macbook running 10.4.9.

I followed James’ directions exactly and did the last two steps where he says we’re “cranking up mysql for local development use…” I think maybe this is where my problem comes from but I’m not sure or sure what to do about it.

I’ve been following along with the book and the install had everything working fine, however now in Task A of the Depot App I’m supposed to issue the command mysqladmin -u root create depot_development and my shell says “mysqladmin: command not found”

why does it do this and what can i do about it? I want to make the database “depot_development” but I don’t know how to do it now that mysqladmin doesn’t work.

Please anyone help.

thanks

Generic-user-small
28 Apr 2007, 13:46
Fora User (865 posts)

Removing the decimal points doesn’t fix it for me. Could someone please post a correct file here? Thanks!

Generic-user-small
01 May 2007, 18:13
Fora User (865 posts)

I solved this by spending a few quality hours with a book on MySQL. I never did understand what actually caused the problem. The solution was to use MySQL to manually add localhost access to the depot database and then to delete all existing tables. After doing this I was able to run rake db/mitigate successfully. Then the application worked as expected.

Generic-user-small
02 May 2007, 22:19
Fora User (865 posts)

I am also receiving this error. All the code is the same as in the book so I’m not sure what the problem is.

Generic-user-small
07 May 2007, 17:07
Fora User (865 posts)

Soooo… highlight works, but did anyone else have the problem that it adds 2 items to the cart each time you click add to cart? I have no idea how to fix this…

Generic-user-small
07 May 2007, 17:06
Fora User (865 posts)

I found the problem (which I don’t understand)

I had an extra @cart.add_product(product) in store_controller.rb here:

… @cart = find_cart @current_item = @cart.add_product(product) @cart.add_product(product) end end

left over from something we did before. thing is, i don’t remember why we had that there or if we need it for something else. is something going to break now?

Generic-user-small
07 May 2007, 17:07
Fora User (865 posts)

that formatted badly, sorry

Generic-user-small
10 May 2007, 22:34
Fora User (865 posts)

Trace the flow through the methods save_order, add_line_items_from_cart, and from_cart_item. Do the controller, order model, and line item model seem suitably decoupled from each other? (One way to tell is to look at potential changes—if you change something, for example by adding a new field to a cart item, does that change ripple through the code?) Can you find a way to further reduce coupling?

“Discussion”:http://wiki.pragprog.com/cgi-bin/wiki.cgi/PT-E-1 of the above task.

I’m not sure I understand the problem, can someone tell me if my assessment makes any sense?

I think the original problem is that the attributes of cart_item are hardcopied into line_item. I am thinking of a solution similar to CartItem? model, perhaps attr_reader used inside LineItem?, but I’m not sure.

You could probably loop through cart_item and map its properties/attributes to line_item, but again I’m not sure you want all of them should your model for cart_item change. I think the best way is to get your attributes from the line_items table, and then grab those out of the cart_item object if they exist.

Generic-user-small
16 May 2007, 06:08
Fora User (865 posts)

I’m getting the same error. I have mysql installed in /usr/local/ and rails installed in /usr/local/src/. No matter what path I put in to reach the msqladmin, Terminal comes back with “-bash: mysqladmin: command not found” (mysql is running, btw).

Any help would be greatly appreciated.

Generic-user-small
19 Jul 2007, 13:40
Fora User (865 posts)

Did over and over again every step: when i click on “add a product” it does work but will not update the cart in the sidebar. I have to refresh the browser to make it show. I checked like 50 times my code against the one on the book. It’s really driving me crazy. Please help me. Thnk you.

Generic-user-small
09 Aug 2007, 21:41
Fora User (865 posts)

I’m getting an error about @cart being null in the line “<%= hidden_div_if(@cart.items.empty? , :id => “cart”) %>” when I hit my checkout button. I don’t know enough about where @cart is being created to understand why.

Help?

Generic-user-small
27 May 2007, 14:45
Fora User (865 posts)

Is it called mysqladmin5 on your system?

Generic-user-small
27 May 2007, 19:15
Fora User (865 posts)

There are two folders. One is an alias named “mysql”. The other is named mysql-5.0.37-osx10.4-powerpc. Inside both of theses folders holds the “bin” folder which lists it as “mysqladmin” only. No “5” anywhere.

Generic-user-small
31 May 2007, 18:26
Fora User (865 posts)

I had the same problem, too. I deleted the session from Firefox and then changed the variable :cart to @cart. It works.

Then I changed the variable @cart back to :cart, and the program still works. So, what is the difference between @cart and :cart?

I know @cart is an instance variable, but what does :cart mean?

Generic-user-small
06 Jun 2007, 00:24
Fora User (865 posts)

Hey all, I am stuck at this same error too. I have the code right, but the error still appears. Please help. Thanks.

Generic-user-small
17 Jun 2007, 08:16
Fora User (865 posts)

I am also having this exact problem, after reaching page 103.

Your solution would be really appreciated!

Generic-user-small
17 Jun 2007, 19:21
Fora User (865 posts)

Hi,

How did you solved it?

Regards,

David

Generic-user-small
19 Jun 2007, 01:36
Fora User (865 posts)

I’m getting the same error:

undefined method `increment_quantity’ for #

And, I’ve already enables the last line above by removing the # sign.

Do you know why I’m still having trouble?

Generic-user-small
22 Jun 2007, 01:57
Fora User (865 posts)

If you make a typo in the execute methods, you’ll try fixing it and rerunning the code, but the table already exists, and that’s a problem. Why? Well, The self.up is trying to create the table then execute the alterations, but those tables already exist, so it raises that message and quits. A quick and dirty way of fixing this, because I don’t know the proper way yet, is to comment out the lines which creates the table then run “rake db:migrate” then uncomment the lines.

I’m sure someone can tell us how to execute the self.down on this one migrate, or the book should go into it later. I just ran into this problem myself reading up to this page, and I have no previous experience with Rails.

Generic-user-small
22 Jun 2007, 02:12
Fora User (865 posts)

A couple things I’d try * shutdown webrick and do a “rake db:sessions:clear”. * check the syntax in the book and make sure all changes are applied. In some cases the book doesn’t do a good job at pointing out all of the changes, so I’d almost suggest selecting the portion, backspace, and then retype the whole thing.

Generic-user-small
25 Jun 2007, 16:46
Fora User (865 posts)

Hmmm… So I was just trying to figure out how I would go about displaying the current orders, as the products are listed (with a Destroy link with them) but I’m having some difficulty…. Any suggestions?

Generic-user-small
25 Jun 2007, 16:46
Fora User (865 posts)

More specifically…..I can get the orders to show up (The stuff from the orders db…but i’m not really sure how to match up stuff from line_items db to the users….

Generic-user-small
11 Jul 2007, 02:31
Fora User (865 posts)

I meet this error,and no matter what I try,is still there,I have spend about 4 hours for this error,but got nothing. anybody help me,please. below is some error information: undefined method `hashed_password=’ for # RAILS_ROOT: ./script/../config/..

Application Trace | Framework Trace | Full Trace D:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/base.rb:1857:in method_missing' #{RAILS_ROOT}/app/models/user.rb:36:in password=’ #{RAILS_ROOT}/app/controllers/login_controller.rb:6:in new' #{RAILS_ROOT}/app/controllers/login_controller.rb:6:in add_user’ D:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/base.rb:1857:in method_missing' D:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/base.rb:1672:in send’ D:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/base.rb:1672:in attributes=' D:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/base.rb:1671:in each’ D:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/base.rb:1671:in attributes=' D:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/base.rb:1505:in initialize_without_callbacks’ D:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/callbacks.rb:225:in initialize' D:/InstantRails/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/base.rb:1095:in send’ D:/InstantRails/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/base.rb:1095:in perform_action_without_filters' D:/InstantRails/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/filters.rb:632:in call_filter’ D:/InstantRails/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/filters.rb:619:in perform_action_without_benchmark' D:/InstantRails/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/benchmarking.rb:66:in perform_action_without_rescue’ D:/InstantRails/ruby/lib/ruby/1.8/benchmark.rb:293:in measure' D:/InstantRails/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/benchmarking.rb:66:in perform_action_without_rescue’ D:/InstantRails/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/rescue.rb:83:in perform_action' D:/InstantRails/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/base.rb:430:in send’ D:/InstantRails/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/base.rb:430:in process_without_filters' D:/InstantRails/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/filters.rb:624:in process_without_session_management_support’ D:/InstantRails/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/session_management.rb:114:in process' D:/InstantRails/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/base.rb:330:in process’ D:/InstantRails/ruby/lib/ruby/gems/1.8/gems/rails-1.2.3/lib/dispatcher.rb:41:in dispatch' D:/InstantRails/ruby/lib/ruby/gems/1.8/gems/mongrel-1.0.1-mswin32/lib/mongrel/rails.rb:78:in process’ D:/InstantRails/ruby/lib/ruby/gems/1.8/gems/mongrel-1.0.1-mswin32/lib/mongrel/rails.rb:76:in synchronize' D:/InstantRails/ruby/lib/ruby/gems/1.8/gems/mongrel-1.0.1-mswin32/lib/mongrel/rails.rb:76:in process’ D:/InstantRails/ruby/lib/ruby/gems/1.8/gems/mongrel-1.0.1-mswin32/lib/mongrel.rb:618:in process_client' D:/InstantRails/ruby/lib/ruby/gems/1.8/gems/mongrel-1.0.1-mswin32/lib/mongrel.rb:617:in each’ D:/InstantRails/ruby/lib/ruby/gems/1.8/gems/mongrel-1.0.1-mswin32/lib/mongrel.rb:617:in process_client' D:/InstantRails/ruby/lib/ruby/gems/1.8/gems/mongrel-1.0.1-mswin32/lib/mongrel.rb:736:in run’ D:/InstantRails/ruby/lib/ruby/gems/1.8/gems/mongrel-1.0.1-mswin32/lib/mongrel.rb:736:in initialize' D:/InstantRails/ruby/lib/ruby/gems/1.8/gems/mongrel-1.0.1-mswin32/lib/mongrel.rb:736:in new’ D:/InstantRails/ruby/lib/ruby/gems/1.8/gems/mongrel-1.0.1-mswin32/lib/mongrel.rb:736:in run' D:/InstantRails/ruby/lib/ruby/gems/1.8/gems/mongrel-1.0.1-mswin32/lib/mongrel.rb:720:in initialize’ D:/InstantRails/ruby/lib/ruby/gems/1.8/gems/mongrel-1.0.1-mswin32/lib/mongrel.rb:720:in new' D:/InstantRails/ruby/lib/ruby/gems/1.8/gems/mongrel-1.0.1-mswin32/lib/mongrel.rb:720:in run’ D:/InstantRails/ruby/lib/ruby/gems/1.8/gems/mongrel-1.0.1-mswin32/lib/mongrel/configurator.rb:271:in run' D:/InstantRails/ruby/lib/ruby/gems/1.8/gems/mongrel-1.0.1-mswin32/lib/mongrel/configurator.rb:270:in each’ D:/InstantRails/ruby/lib/ruby/gems/1.8/gems/mongrel-1.0.1-mswin32/lib/mongrel/configurator.rb:270:in run' D:/InstantRails/ruby/lib/ruby/gems/1.8/gems/mongrel-1.0.1-mswin32/bin/mongrel_rails:127:in run’ D:/InstantRails/ruby/lib/ruby/gems/1.8/gems/mongrel-1.0.1-mswin32/lib/mongrel/command.rb:211:in run' D:/InstantRails/ruby/lib/ruby/gems/1.8/gems/mongrel-1.0.1-mswin32/bin/mongrel_rails:243 D:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activesupport-1.4.2/lib/active_support/dependencies.rb:488:in load’ D:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activesupport-1.4.2/lib/active_support/dependencies.rb:488:in load' D:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activesupport-1.4.2/lib/active_support/dependencies.rb:342:in new_constants_in’ D:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activesupport-1.4.2/lib/active_support/dependencies.rb:488:in load' D:/InstantRails/ruby/lib/ruby/gems/1.8/gems/rails-1.2.3/lib/commands/servers/mongrel.rb:60 D:/InstantRails/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in gem_original_require’ D:/InstantRails/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in require' D:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activesupport-1.4.2/lib/active_support/dependencies.rb:495:in require’ D:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activesupport-1.4.2/lib/active_support/dependencies.rb:342:in new_constants_in' D:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activesupport-1.4.2/lib/active_support/dependencies.rb:495:in require’ D:/InstantRails/ruby/lib/ruby/gems/1.8/gems/rails-1.2.3/lib/commands/server.rb:39 D:/InstantRails/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in gem_original_require' D:/InstantRails/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in require’ script/server:3 D:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/base.rb:1857:in method_missing' #{RAILS_ROOT}/app/models/user.rb:36:in password=’ D:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/base.rb:1672:in send' D:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/base.rb:1672:in attributes=’ D:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/base.rb:1671:in each' D:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/base.rb:1671:in attributes=’ D:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/base.rb:1505:in initialize_without_callbacks' D:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/callbacks.rb:225:in initialize’ #{RAILS_ROOT}/app/controllers/login_controller.rb:6:in new' #{RAILS_ROOT}/app/controllers/login_controller.rb:6:in add_user’ D:/InstantRails/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/base.rb:1095:in send' D:/InstantRails/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/base.rb:1095:in perform_action_without_filters’ D:/InstantRails/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/filters.rb:632:in call_filter' D:/InstantRails/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/filters.rb:619:in perform_action_without_benchmark’ D:/InstantRails/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/benchmarking.rb:66:in perform_action_without_rescue' D:/InstantRails/ruby/lib/ruby/1.8/benchmark.rb:293:in measure’ D:/InstantRails/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/benchmarking.rb:66:in perform_action_without_rescue' D:/InstantRails/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/rescue.rb:83:in perform_action’ D:/InstantRails/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/base.rb:430:in send' D:/InstantRails/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/base.rb:430:in process_without_filters’ D:/InstantRails/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/filters.rb:624:in process_without_session_management_support' D:/InstantRails/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/session_management.rb:114:in process’ D:/InstantRails/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/base.rb:330:in process' D:/InstantRails/ruby/lib/ruby/gems/1.8/gems/rails-1.2.3/lib/dispatcher.rb:41:in dispatch’ D:/InstantRails/ruby/lib/ruby/gems/1.8/gems/mongrel-1.0.1-mswin32/lib/mongrel/rails.rb:78:in process' D:/InstantRails/ruby/lib/ruby/gems/1.8/gems/mongrel-1.0.1-mswin32/lib/mongrel/rails.rb:76:in synchronize’ D:/InstantRails/ruby/lib/ruby/gems/1.8/gems/mongrel-1.0.1-mswin32/lib/mongrel/rails.rb:76:in process' D:/InstantRails/ruby/lib/ruby/gems/1.8/gems/mongrel-1.0.1-mswin32/lib/mongrel.rb:618:in process_client’ D:/InstantRails/ruby/lib/ruby/gems/1.8/gems/mongrel-1.0.1-mswin32/lib/mongrel.rb:617:in each' D:/InstantRails/ruby/lib/ruby/gems/1.8/gems/mongrel-1.0.1-mswin32/lib/mongrel.rb:617:in process_client’ D:/InstantRails/ruby/lib/ruby/gems/1.8/gems/mongrel-1.0.1-mswin32/lib/mongrel.rb:736:in run' D:/InstantRails/ruby/lib/ruby/gems/1.8/gems/mongrel-1.0.1-mswin32/lib/mongrel.rb:736:in initialize’ D:/InstantRails/ruby/lib/ruby/gems/1.8/gems/mongrel-1.0.1-mswin32/lib/mongrel.rb:736:in new' D:/InstantRails/ruby/lib/ruby/gems/1.8/gems/mongrel-1.0.1-mswin32/lib/mongrel.rb:736:in run’ D:/InstantRails/ruby/lib/ruby/gems/1.8/gems/mongrel-1.0.1-mswin32/lib/mongrel.rb:720:in initialize' D:/InstantRails/ruby/lib/ruby/gems/1.8/gems/mongrel-1.0.1-mswin32/lib/mongrel.rb:720:in new’ D:/InstantRails/ruby/lib/ruby/gems/1.8/gems/mongrel-1.0.1-mswin32/lib/mongrel.rb:720:in run' D:/InstantRails/ruby/lib/ruby/gems/1.8/gems/mongrel-1.0.1-mswin32/lib/mongrel/configurator.rb:271:in run’ D:/InstantRails/ruby/lib/ruby/gems/1.8/gems/mongrel-1.0.1-mswin32/lib/mongrel/configurator.rb:270:in each' D:/InstantRails/ruby/lib/ruby/gems/1.8/gems/mongrel-1.0.1-mswin32/lib/mongrel/configurator.rb:270:in run’ D:/InstantRails/ruby/lib/ruby/gems/1.8/gems/mongrel-1.0.1-mswin32/bin/mongrel_rails:127:in run' D:/InstantRails/ruby/lib/ruby/gems/1.8/gems/mongrel-1.0.1-mswin32/lib/mongrel/command.rb:211:in run’ D:/InstantRails/ruby/lib/ruby/gems/1.8/gems/mongrel-1.0.1-mswin32/bin/mongrel_rails:243 D:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activesupport-1.4.2/lib/active_support/dependencies.rb:488:in load' D:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activesupport-1.4.2/lib/active_support/dependencies.rb:488:in load’ D:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activesupport-1.4.2/lib/active_support/dependencies.rb:342:in new_constants_in' D:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activesupport-1.4.2/lib/active_support/dependencies.rb:488:in load’ D:/InstantRails/ruby/lib/ruby/gems/1.8/gems/rails-1.2.3/lib/commands/servers/mongrel.rb:60 D:/InstantRails/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in gem_original_require' D:/InstantRails/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in require’ D:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activesupport-1.4.2/lib/active_support/dependencies.rb:495:in require' D:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activesupport-1.4.2/lib/active_support/dependencies.rb:342:in new_constants_in’ D:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activesupport-1.4.2/lib/active_support/dependencies.rb:495:in require' D:/InstantRails/ruby/lib/ruby/gems/1.8/gems/rails-1.2.3/lib/commands/server.rb:39 D:/InstantRails/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in gem_original_require’ D:/InstantRails/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in `require’ script/server:3 Request Parameters: {“user”=>{“name”=>””, “password_confirmation”=>””, “password”=>””}, “commit”=>”Add user”}

Show session dump


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

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

Generic-user-small
10 Jul 2007, 14:49
Fora User (865 posts)

hi,

I am getting the following error..please see and tell me …what is the problem ?

NoMethodError in AdminController#create

undefined method `image_url’ for #

RAILS_ROOT: ./script/../config/..

regards kapil

Generic-user-small
10 Jul 2007, 14:49
Fora User (865 posts)

Figured it out myself

–> in 001_create_product.rb,I used t.column :img_url, :string

–> while,in 003_add_test_data.rb,I was trying to

    :image_url => '/images/utc.jpg',

–> so just converted :image_url to :img_url

–> also,changed in the model

validates_format_of :img_url, :with => %r{.(gif|jpg|png)$}i, :message => “must be a URL for a GIF, JPG, or PNG image”

Generic-user-small
10 Jul 2007, 15:24
Fora User (865 posts)

Same problem here….

I am using 2nd edition of the book where

I have added the following line in 002_add_prices.rb add_column:products,:price,:decimal,:precision=>8,:scale=>2,:default=>0

Now by downloading the book code in 003

Product.create(:title => 'Pragmatic Project Automation',
:description => 
%{<p>
   <em>Pragmatic Project Automation</em> shows you how to improve the 
   consistency and repeatability of your project's procedures using 
   automation to reduce risk and errors.
  </p>
  <p>
    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.
  </p>},
:img_url =>   '/images/auto.jpg',    
:price => 2995)

nothing is happening.everything succeeds successfully.

no error butwhen I check the database table its empty

Generic-user-small
11 Jul 2007, 02:31
Fora User (865 posts)

I solved it,I misspelled the field ‘hashed_password’ to ‘password’,I fixed it then everything goes well.

Generic-user-small
17 Jul 2007, 10:48
Fora User (865 posts)

o/ I made the mistake too!

How can so many people make this mistake?

Ah well. Good old google brought me here :)

Generic-user-small
18 Jul 2007, 07:38
Fora User (865 posts)

when i destroy someting it ask me “are you sure?”,if I push the Ok button my app collapsed,and throw a exception like”Couldn’t find XXX with ID=12”,but the line id of 12 deleted successful.if I push the Cancel button everything works well,the line is deleted and it redirect to the index page.It looks that the Cancel button do the Ok button’s work,this almost makes me mad,please help,thanks. this is my view code: “ <%= link_to ‘Destroy’, { :action => ‘destroy’, :id => feature }, :confirm => ‘Are you sure?’, :post => true %>”,and this is my controller code: “ def destroy Feature.find(params[:id]).destroy redirect_to_index(‘Deleted.’) end “

Generic-user-small
18 Jul 2007, 18:34
Fora User (865 posts)

I tried several times to clear sessions and stuff like that (application reboot, even computer reboot !), but I never worked. I JUST found a solution though, which consists in adding :update in the form_remote_tag.

Code in the book (p129) :

<% form_remote_tag :url => { :action => :add_to_cart, :id => product } do %>

My code :

<% form_remote_tag :url => { :action => :add_to_cart, :id => product }, :update => "cart" do %>

Hope this will help someone !

Generic-user-small
18 Jul 2007, 18:55
Fora User (865 posts)

Back again. In fact, my solution doesn’t use add_to_cart.rjs anymore, which changes everything (you won’t be able to do the next step of the tutorial…).

Generic-user-small
18 Jul 2007, 18:55
Fora User (865 posts)

Back again. In fact, my solution doesn’t use add_to_cart.rjs anymore, which changes everything (you won’t be able to do the next step of the tutorial…).

Generic-user-small
19 Jul 2007, 12:25
Fora User (865 posts)

I am having the same problem.

I found out the issue is with the visual effects. Check out your add_to_cart.rjs file and remove everything but the

page.replace_html( “cart”, :partial => “cart”, :object => @cart )

And it works. I’ve tried for 4-5 hours to get the visual effects to work. None of them do on the cart. I’ve taken sample code from other online sites and slapped them into single pages (using visual effects) and they do work. So scriptaculous works, just not with the cart (visual effects, anyway)

cbmeeks http://eblarg.com

Generic-user-small
19 Jul 2007, 12:29
Fora User (865 posts)

I am having the same problem. It is with the visual_effects.

My log file reports:

ERROR: compiling _run_rjs_47app47views47store47add_to_cart46rjs RAISED compile error script/../config/../app/views/store/add_to_cart.rjs:1: syntax error, unexpected tIDENTIFIER, expecting kEND page[:current_item].visual_effect :highlight, :startcolor => “#88ff88”, :endcolor => “#114411” ^ Function body: def _run_rjs_47app47views47store47add_to_cart46rjs(local_assigns) controller.response.content_type ||= ‘text/javascript’ update_page do |page| page[:current_item].visual_effect :highlight, :startcolor => “#88ff88”, :endcolor => “#114411” end end Backtrace: script/../config/../app/views/store/add_to_cart.rjs:3:in `compile_template’ ……

I have no idea what to do as I am new with AJAX/JS. This is why I hate JS. I spend 95% of my time debugging JS

cbmeeks

http://eblarg.com

Generic-user-small
19 Jul 2007, 13:40
Fora User (865 posts)

I had the same problem. It came from some code I put in application.rb in order to set encoding to utf8. The code I took on the net wasn’t taking good care of xhr requests…

Maybe this can help.

Generic-user-small
20 Jul 2007, 10:41
Fora User (865 posts)

Thanks Andre!

Generic-user-small
20 Jul 2007, 15:21
Fora User (865 posts)

None of these solutions work for me. It’s like this method:

def total_price @items.sum { |item| item.price } end

…is not visible in “depot/app/models/cart.rb”, although the application has no trouble seeing “add_product” in that file.

I’m a newbie, but my guesses are: (1) there’s a problem becasue of the “cart.rb” file that also exists in the controller folder. (2) the “total_price” method is evaluating to null

Check this out…I modified the method to just return a value, like this:

def total_price # @items.sum { |item| item.price } return 4000 end

…and I still get: NoMethodError in Store#add_to_cart

Showing app/views/store/add_to_cart.rhtml where line #18 raised: undefined method `total_price’ for #

I’m ready to bail on this book. I read some nasty comments about situations like this on Barnes and Noble.

Generic-user-small
01 Aug 2007, 20:52
Fora User (865 posts)

I have the same problem… anyone got a solution for this one?

Generic-user-small
01 Aug 2007, 21:35
Fora User (865 posts)

I found the error i my case. It was because address was mispelled, I spelled it adress instead of address several places.

Generic-user-small
03 Aug 2007, 04:32
Fora User (865 posts)

I´m reading the “Agile Web Development with Rails 2nd Edition” and in the “depot” example I have problems with the decimal numbers. The data are stored normally, but a number like ‘29.95’ are visualized like ‘29.0’ in the browser. Does somebody help? My software´s versions are: Ruby - ruby 1.8.5 (2006-12-25 patchlevel 12) [i386-mswin32] Rails - Rails 1.2.3 SQL Server 2000 SP4 Thanks!

Generic-user-small
09 Aug 2007, 21:41
Fora User (865 posts)

You’ve probably figured this out by now, but I had the exact same issue. What happened is you put the “def checkout” code block after the “private” keyword in the store_controller.rb. If you move it to before the store_controller.rb, it will magically work.

Generic-user-small
26 Aug 2007, 04:18
Fora User (865 posts)

When I click on the Place Order button (whether I have entered information into the form fields or not), it just refreshes the page with the fields emptied out. Does anyone have any insight into why this would be? I’ve gone through the chapter 3 or 4 times now double-checking my code. What’s weird is that it doesn’t even flash any of the validation errors, so it’s as if the button isn’t mapped to the correct function, or the function doesn’t operate properly.

Any help is much appreciated.

Thanks! Paul

Generic-user-small
26 Aug 2007, 04:18
Fora User (865 posts)

Well well, all it took was for me to post to a forum to find my problem. it was indeed a typo in the checkout.rhtml form code. now i feel like the dumb one…

Generic-user-small
28 Aug 2007, 10:40
Fora User (865 posts)

when i ‘add_user’ to post the form ,the error “undefined method `hashed_password=’ for #" shows ...

for update the error ,i copy the example sources to my project,but it still have the problem… so ,help me…

thank you ….

oliver

===================================================== full trace:

d:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/base.rb:1857:in method_missing' #{RAILS_ROOT}/app/models/user.rb:40:in password=’ d:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/base.rb:1672:in send' d:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/base.rb:1672:in attributes=’ d:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/base.rb:1671:in each' d:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/base.rb:1671:in attributes=’ d:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/base.rb:1505:in initialize_without_callbacks' d:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/callbacks.rb:225:in initialize’ #{RAILS_ROOT}/app/controllers/login_controller.rb:39:in new' #{RAILS_ROOT}/app/controllers/login_controller.rb:39:in add_user’ d:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/base.rb:1095:in send' d:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/base.rb:1095:in perform_action_without_filters’ d:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/filters.rb:632:in call_filter' d:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/filters.rb:619:in perform_action_without_benchmark’ d:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/benchmarking.rb:66:in perform_action_without_rescue' d:/ruby/lib/ruby/1.8/benchmark.rb:293:in measure’ d:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/benchmarking.rb:66:in perform_action_without_rescue' d:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/rescue.rb:83:in perform_action’ d:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/base.rb:430:in send' d:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/base.rb:430:in process_without_filters’ d:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/filters.rb:624:in process_without_session_management_support' d:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/session_management.rb:114:in process’ d:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/base.rb:330:in process' d:/ruby/lib/ruby/gems/1.8/gems/rails-1.2.3/lib/dispatcher.rb:41:in dispatch’ d:/ruby/lib/ruby/gems/1.8/gems/rails-1.2.3/lib/webrick_server.rb:113:in handle_dispatch' d:/ruby/lib/ruby/gems/1.8/gems/rails-1.2.3/lib/webrick_server.rb:79:in service’ d:/ruby/lib/ruby/1.8/webrick/httpserver.rb:104:in service' d:/ruby/lib/ruby/1.8/webrick/httpserver.rb:65:in run’ d:/ruby/lib/ruby/1.8/webrick/server.rb:173:in start_thread' d:/ruby/lib/ruby/1.8/webrick/server.rb:162:in start’ d:/ruby/lib/ruby/1.8/webrick/server.rb:162:in start_thread' d:/ruby/lib/ruby/1.8/webrick/server.rb:95:in start’ d:/ruby/lib/ruby/1.8/webrick/server.rb:92:in each' d:/ruby/lib/ruby/1.8/webrick/server.rb:92:in start’ d:/ruby/lib/ruby/1.8/webrick/server.rb:23:in start' d:/ruby/lib/ruby/1.8/webrick/server.rb:82:in start’ d:/ruby/lib/ruby/gems/1.8/gems/rails-1.2.3/lib/webrick_server.rb:63:in dispatch' d:/ruby/lib/ruby/gems/1.8/gems/rails-1.2.3/lib/commands/servers/webrick.rb:59 d:/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in gem_original_require’ d:/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in require' d:/ruby/lib/ruby/gems/1.8/gems/activesupport-1.4.2/lib/active_support/dependencies.rb:495:in require’ d:/ruby/lib/ruby/gems/1.8/gems/activesupport-1.4.2/lib/active_support/dependencies.rb:342:in new_constants_in' d:/ruby/lib/ruby/gems/1.8/gems/activesupport-1.4.2/lib/active_support/dependencies.rb:495:in require’ d:/ruby/lib/ruby/gems/1.8/gems/rails-1.2.3/lib/commands/server.rb:39 d:/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in gem_original_require' d:/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in require’ script/server:3

Generic-user-small
04 Sep 2007, 02:38
Fora User (865 posts)

I nearly tore my hair out over this one too. Turns out I didn’t change the ~~~ @items ~~~ concatenation and had left it as ~~~ CartItem.new(product) ~~~

It’s supposed to be ~~~ @items « current_item ~~~

Generic-user-small
04 Sep 2007, 17:33
Fora User (865 posts)

@Randy Walker: you’re a genius.

I’ve tried everything I know (which isn’t much) for the past hour, then seeing your post I realized the code was in the wrong .rjs file.

Sum of how I got it working – first replacing the ‘Submit’ tag in _cart.rhtml:

  <% form_remote_tag :url => { :action => :empty_cart } do %>
    <%= submit_tag 'Empty cart' %>
  <% end %>

And to blind_up the div (this goes in empty_cart.rjs):

  page[:cart].visual_effect :blind_up

Note that you can paste the percent signs if you use the pre and code tags.

  • slr
Generic-user-small
10 Sep 2007, 14:31
Fora User (865 posts)

Hey guys,

I have been trying to implement the login example from the book (chapter 11). I have followed everything as stated except I’m using a field called ‘username’ instead of name used by the book.

The error that i get is “NoMethodError in LoginController#login

undefined method `salt’ for kala“

I would really appreciate any suggestions.

Regards

Raj

Generic-user-small
10 Sep 2007, 02:52
Fora User (865 posts)

Hi Raj,

I came here looking for the same solution. Undefined method as far as I can tell means that you don’t have a column in your table named salt. Aleast that was what the problem was for me.

Generic-user-small
10 Sep 2007, 14:31
Fora User (865 posts)

Yeah i resolved it as well was a simple typo :-)

Thanks anyways.

Cheers

Generic-user-small
11 Sep 2007, 04:29
Fora User (865 posts)

So it seems like with the Depot app in Chapter 8, if there are thousands of users using the website, there will be thousands or tens of thousands of CartItem objects in the server’s RAM…. and the Cart object contains the array that tells which user has which CartItem objects…

Now, I tried this to see how many CartItem object there are:

in model/cart_item.rb, i added the class variable @@count

class CartItem

attr_reader :product, :quantity

@@count = 0

def initialize(product) @product = product @quantity = 1 @@count += 1

end

def self.count @@count end

def count @@count end

and in store.rhtml, i add the following to the LEFT column of the page

Number of CartItem <%= CartItem.count %>

but I tried adding items after items… the count just won’t go from 1 to 2, 3, 4, 5, 6 but will just keep on being either 0 or 1. Any thoughts as to why?

Generic-user-small
11 Sep 2007, 04:29
Fora User (865 posts)

the above line should read

<%= CartItem.count %> (which is ERB showing the CartItem.count ) maybe this BBS won’t allow showing the percent sign

Generic-user-small
12 Sep 2007, 19:44
Fora User (865 posts)

I get a similar error with mine it says RJS Error: TypeError $(element) has no properties then a message window pops up with a bunch of information which I presume was sent to the browser from the server. I haven’t found a fix for it yet but when I do I’ll repost.

Generic-user-small
13 Sep 2007, 15:58
Fora User (865 posts)

Okay, simple programmer error here is what was doing me in. The .rjs file we create in D2 is looking for something tagged <div id="cart"> on the page in which it’s displayed. In this case that’d be the store.rhtml file where we put the cart in the sidebar. Check to make sure your listing for that file is the same as the listing on pages 116-117 of the second edition and you should be fine.

Generic-user-small
13 Sep 2007, 16:00
Fora User (865 posts)

Okay so my tag didn’t make it in here. Either you can view it in the source or just look on page 117 of the second edition at the three lines with the little triangles pointing at them.

Generic-user-small
13 Sep 2007, 21:13
Fora User (865 posts)

I’m following along with the book in chapter 6. I added “scaffold :product” to the AdminController class as described on page 67. But when I browse to http://localhost:3000/admin all I get is the following error:

undefined method `paginate’ for #

I have no idea what to do to fix this problem. Any help would be greatly appreciated.

Generic-user-small
18 Oct 2007, 10:27
小乐 (2 posts)

我也遇到 RJS Error: TypeError $(element)… 的问题。 请问如何解决? E-mail:369035906@qq.com

Generic-user-small
18 Oct 2007, 10:43
小乐 (2 posts)

HO page[:current_item].visual_effect :highlight,{:startcolor => “#88ff88”, :endcolor => “#114411” } if @current_item can fix it

Tito@carmel (closeup)_pragsmall
20 Oct 2007, 23:22
Tito Ciuro (1 post)

So far so good following the app. However, I have a question about page 159:

`
class LoginController < ApplicationController

before_filter :authorize, :except => :login
`

I fail to understand this part. Can someone pleas explain this to me?

Thanks,

-- Tito
Generic-user-small
21 Oct 2007, 00:30
Brian Boyl (4 posts)

First off, thanks for what so far is a great book!

Reached page 92 with everything working as expected, but when I rendered admin/list after styling the page (using the downloaded versions of list.rhtml, admin.rhtml, and depot.css), things were in the right place, but the styling wasn’t working. In other words, it seemed to be ignoring the css.

On further inspection of the generated html (viewing the source of admin/list in Firefox) I found that the admin layout was not being included in the code: It had no html header and hence no css declaration. That’s why my styling wasn’t taking. It seems my installation of rails is not wrapping the admin.rhtml layout around the list.rhtml.

Why is this happening? Is there something I can do to fix it?

Thanks in advance for any help.

Generic-user-small
21 Oct 2007, 08:58
dx111ge (1 post)

page 74 german version … the downloads (depot.css) are not available …. but they just say download the css . very frustrating Good Book, but may be like in other books the should add a cd with the code and than a more forum like Forum instead such a blog style thing , sorry, this blog is not so usefull for a data oriented person :-)

Generic-user-small
21 Oct 2007, 18:32
Sebastien Lamy (2 posts)

I saw a message of Fora User telling there was a lot of problem with the ~~~ cart_item == @current_item ~~~ in the cart_item.rhtml file, when enabling ajax (p.139 if the french version).

The poster resolved the problem by replacing the @== @ by the @ .equal @ method, wich is never overidden.

This problem comes clearly from the fact that his CartItem class inherit ActiveRecord Class (this is because he generated his “cart_item.rb” file using the model script generator). So as this poster noticed, the @==@ operator was overidden and caused error. ActiveRecord objects suppose there are records corresponding to the Class in the database, and this is not the case for our CartItem class

The CartItem class should not inherit from another class, and everything will be fine. So if you have this problem, check your cart_item.rb file in your models

Generic-user-small
21 Oct 2007, 19:21
Full Name (1 post)

I’ve just run into my first problem on page 97(pdf). When I refresh my browser, after just changing /app/views/store/index.rhtml, I get this error:

Errno::ENOENT in StoreController#index

No such file or directory - /var/run/mysqld/mysqld.sock

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

/usr/lib/ruby/gems/1.8/gems/activerecord-1.15.5/lib/active_record/vendor/mysql.rb:107:in initialize' /usr/lib/ruby/gems/1.8/gems/activerecord-1.15.5/lib/active_record/vendor/mysql.rb:107:in new’ /usr/lib/ruby/gems/1.8/gems/activerecord-1.15.5/lib/active_record/vendor/mysql.rb:107:in real_connect' /usr/lib/ruby/gems/1.8/gems/activerecord-1.15.5/lib/active_record/connection_adapters/mysql_adapter.rb:389:in connect’ /usr/lib/ruby/gems/1.8/gems/activerecord-1.15.5/lib/active_record/connection_adapters/mysql_adapter.rb:152:in initialize' /usr/lib/ruby/gems/1.8/gems/activerecord-1.15.5/lib/active_record/connection_adapters/mysql_adapter.rb:82:in new’ /usr/lib/ruby/gems/1.8/gems/activerecord-1.15.5/lib/active_record/connection_adapters/mysql_adapter.rb:82:in mysql_connection' /usr/lib/ruby/gems/1.8/gems/activerecord-1.15.5/lib/active_record/connection_adapters/abstract/connection_specification.rb:262:in send’ /usr/lib/ruby/gems/1.8/gems/activerecord-1.15.5/lib/active_record/connection_adapters/abstract/connection_specification.rb:262:in connection_without_query_cache=' /usr/lib/ruby/gems/1.8/gems/activerecord-1.15.5/lib/active_record/query_cache.rb:54:in connection=’ /usr/lib/ruby/gems/1.8/gems/activerecord-1.15.5/lib/active_record/connection_adapters/abstract/connection_specification.rb:230:in retrieve_connection' /usr/lib/ruby/gems/1.8/gems/activerecord-1.15.5/lib/active_record/connection_adapters/abstract/connection_specification.rb:78:in connection’ /usr/lib/ruby/gems/1.8/gems/activerecord-1.15.5/lib/active_record/base.rb:1139:in add_limit!' /usr/lib/ruby/gems/1.8/gems/activerecord-1.15.5/lib/active_record/base.rb:1101:in construct_finder_sql’ /usr/lib/ruby/gems/1.8/gems/activerecord-1.15.5/lib/active_record/base.rb:997:in find_every' /usr/lib/ruby/gems/1.8/gems/activerecord-1.15.5/lib/active_record/base.rb:418:in find’ /home/me/Programming/Ruby/Dev/depot/app/models/product.rb:4:in find_products_for_sale' /home/me/Programming/Ruby/Dev/depot/app/controllers/store_controller.rb:4:in index’

what’s wrong?

Generic-user-small
24 Oct 2007, 06:33
michael dorian (1 post)

Can someone help me with the “Playtime” Assignment on page 154?

(The list of possible payment types is currently stored as a constant in the Order class. Can you move this list into a database table? Can you still make validation work for the field?)

It appears the “RailsPlayTime” Wiki is no longer available and all the hints for this assignment banished to the depths of space.

How did you guys go about making this work. I can’t seem to figure it out and form.select helper is no where to be seen in the API documentation.

Thanks.

Generic-user-small
25 Oct 2007, 14:39
Max Williams (1 post)

I don’t mean offence to anyone, but this forum has everyone’s posts all just sort of jumbled up together when i look at it, so i can’t see who’s posted a question, who’s replied to it etc. Is that how it’s meant to look or do i have some weird browser error?

Generic-user-small
28 Oct 2007, 04:11
Brian Boyl (4 posts)

In the AJAX example, second edition, “Iteration D2”, page 130, PDF, I click on add to cart and the cart does not update. I’m even using the downloaded code and still no go. But when I reload the page it updates fine.

Seems the data’s working properly, but AJAX does not signal the cart to update when the button is clicked.

Noticed that someone above had a similar problem and placed an “update” command in the JavaScript generator in the .rjs file. When I do that I get an error where the cart should be.

Anyone have a solution?

Generic-user-small
28 Oct 2007, 04:02
Brian Boyl (4 posts)

Max,

I see the same thing. A bunch of “fora users” and very few others. Makes it really rough to get solid information from here.

Generic-user-small
29 Oct 2007, 00:27
Brian Boyl (4 posts)

This is in reference to the AJAX problem I had on page 130, noted above. I still don’t know why my attempts on page 130 didn’t work (and still don’t), but I did the following few pages - the yellow flash effect - and it worked fine (page 133).

Anyone have a hunch as to why?

Dave_gnome_head_isolated_pragsmall
29 Oct 2007, 17:53
Dave Thomas (390 posts)

The reason for the “fora users” is that we imported all the discussions from the old system, and that system didn’t have accounts, so we can’t tie things together.

It’s a compromise.

Generic-user-small
04 Nov 2007, 19:34
make (1 post)

Im currently working through Chapter 10 Task E “Check Out!”

When I go to submit the form with the customer details on, I get the following error:

"NameError in StoreController#save_order

undefined local variable or method `line_items' for #<Order:0x48f53a0>

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

C:/ruby/ruby/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/base.rb:1860:in `method_missing'
#{RAILS_ROOT}/app/models/order.rb:15:in `add_line_items_from_cart'
#{RAILS_ROOT}/app/models/order.rb:13:in `each'
#{RAILS_ROOT}/app/models/order.rb:13:in `add_line_items_from_cart'
#{RAILS_ROOT}/app/controllers/store_controller.rb:44:in `save_order'
-e:4:in `load'
-e:4"

Ive tried looking trhough everything and have even backtracked about 30 pages in teh book to see if theres anything Ive missed but havent found anything.

Also, while working through the AJAX section previous to this, I didnt get the cart to refresh without actually refreshing the whole page nor did I get the colour highlight effect when adding items.

Im using instantrails on XP SP2 with firefox 2

Generic-user-small
08 Nov 2007, 22:15
Lloyd Blake (5 posts)

Hi I’ve entered the code required to get the cart working (upto page 102). However, when I try to ‘add to cart’ I get the following errors:

You have a nil object when you didn’t expect it! The error occurred while evaluating nil.items

and

Extracted source (around line #4):

1: Your Pragmatic Cart 2: 3: <ul> 4: <% for cart_item in @cart.items %> 5: <li><%= cart_item.quantity %> × <%= h(cart_item.title) %></li> 6: <% end %> 7: </ul>

I’ve changed a piece of the code in the ‘store_controller.rb’ from

def find_cart session[:cart] ||= Cart.new end

to

def find_cart session[@cart] ||= Cart.new end

I know its passing in a null value for ‘Cart’ but I can’t see where it is? Can someone tell me where I am going wrong please?

Generic-user-small
09 Nov 2007, 04:37
Bill Barnard (4 posts)

Lloyd,

I think that your find_cart method doesn’t work because @cart itself is nil. find_cart is supposed to return a value that can be assigned to @cart. I think it’s possible to use any object as a hash key; in this case it seems easiest to use a constant, e.g. the symbol :cart, rather than the instance variable @cart. I’m not sure how you’d retrieve the Cart using the instance variable as a key…

Generic-user-small
09 Nov 2007, 08:57
Lloyd Blake (5 posts)

Bill,

I did use the

def find_cart session[:cart] ||= Cart.new end

method but I still got the same error. I’ll probably delete all the files relating to this and start from scratch and see if I get the same error. Or has anyone had the same issue when developing their cart?

Generic-user-small
09 Nov 2007, 16:56
Bill Barnard (4 posts)

Lloyd,

I hope this isn’t a totally stupid question…, but does your code still use find_cart to assign a value to @cart? If so, and @cart is still nil, then maybe Cart.new is returning nil…

I’d suggest making use of Logger (see Section 14.5 of the book) to help you narrow your search.

Generic-user-small
10 Nov 2007, 11:03
Lloyd Blake (5 posts)

Bill,

The issue has been resolved I copied the ‘store controller.rb’ from the code example in depot_f and it worked!! I must have missed something when I typed the code in?

Thanks for your input

Generic-user-small
15 Nov 2007, 16:53
Dominic Amann (2 posts)

I am up to the point where we add cart-item quantities (pg 101 a smarter cart)

In using the example code, I get:

NoMethodError in Store#add_to_cart

Showing app/views/store/add_to_cart.rhtml where line #5 raised:

undefined method `quantity’ for #

I have run rake db:sessions:clear, restarted the web server, and cleared the browser cache but I still get the error. I have gone over the code with a fine toothed comb, but I cannot find my mistake. Any clues for a hapless n00b?

Bah - just fixed. One of the oldest mistakes in the booK: I had some unsaved edits in my editor!

Generic-user-small
17 Nov 2007, 19:57
Randall Desmond (5 posts)

Section 11.3, Iteration F3 (page 166 in a recently generated PDF), regarding the method ‘authorize’…

“Where should we put this method? It could sit directly in the admin controller, but, for reasons that will become apparent shortly, let’s put it instead in the ApplicationController, the parent class of all our controllers.”

I missed the apparent reasons. Can someone clue me in?

Thanks!

Generic-user-small
18 Nov 2007, 04:42
Dan Brown (1 post)

Randall - The reason that you would place the authorize action in the ApplicationController, is so that it is available to all controllers (or at least the one’s that you wish to restrict access to), without having to recreate the authorize action in each controller. Since the ApplicationController is a “parent” class, the controllers that you create (i.e. store, admin) will inherit from it. Hope this helps.

Generic-user-small
18 Nov 2007, 06:14
Randall Desmond (5 posts)

It helps. I missed putting the ‘before_filter’ call in my admin controller - so I didn’t make that connection. oops!

Thanks Dan.

Huguesbrunelle_pragsmall
20 Nov 2007, 20:10
Hugues Brunelle (1 post)

Chapter 9. Task D: Add a Dash of AJAX * Point 4 : Add a link next to each item in the cart. When clicked it shold invoke an action to decrement the quantity of the item, deleting it from the cart when the quantity reaches zero. Get it working without using AJAX first, and then add the AJAX goodness.

Ok so I’ve been doing this chapter and got stuck on that point for like 2 hours. So here is what I’ve been up to, I got it work except for doing an highlight effect on decrement. Anyone can help me out with this?

So here are my sources :

cart.rb

  def remove_product(product)
    current_item = @items.find {|item| item.product == product}
    if current_item.quantity > 1
      current_item.decrement_quantity
    else
      @items.delete(current_item)
    end
    current_item
  end

cart_item.rb

  def decrement_quantity
    @quantity -= 1
  end

store_controller.rb

  def remove_from_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.remove_product(product)
      redirect_to_index unless request.xhr?
    end
  end

remove_from_cart.rjs

  page.replace_html("cart", :partial => "cart", :object => @cart)

So if anyone has an idea how I could get the highlight effect on removing current_item, that would be cool

Generic-user-small
21 Nov 2007, 09:30
Ravi (1 post)

ActiveRecord::RecordNotFound in StoreController#add_to_cart

Couldn’t find Product without an ID

i was doing page no. 109 and after doing all the things i got the above error.

Generic-user-small
24 Nov 2007, 22:35
Rob Brasington (1 post)

As a follow up to Hugues Brunelle post on Nov 20. Adding this to remove_from_cart.rjs seems to work ok.

` 
page.select("tr#current_item").each { |tr| tr.visual_effect :highlight, 
                                  :startcolor => "#88ff88",
                                  :endcolor => "#114411" }								
`

Using the each method prevents problems when the quantity is taken down to zero. This is very similar to technique shown in the book for hiding the flash notice after a checkout, and then adding an item to the new cart.
Generic-user-small
27 Nov 2007, 21:18
Cade D. (1 post)

Maybe it’s all in my head, but I’m having the strangest little issue ever. My pricetags in my rails app are always whole numbers. Rails seems to completely ignore my decimal input. So as a consequence, 10.41 becomes 10.00, always.

Here’s some worthwhile stuff:

within my 001_create_products.rb file: :price, :decimal, :percision => 2, :default => 0 And calling the product price in a view: <%= number_to_currency(product.price, {:precision => 2}) %> That’s all I can really think of that could be of help. Is this all in my head, or am I retarded and missing something?

Generic-user-small
28 Nov 2007, 18:02
Bill Barnard (4 posts)

Cade,

You may want to check the “percision” of your typing in 001_create_products.rb…

Generic-user-small
04 Dec 2007, 09:48
Karsten Wilke (3 posts)

I have a problem when i want to delete the last user. It works even if i get a message that the last user can not be deleted. Is it possible that the problem comes from that line

if User.count.zero? rais “cant delete last user” end

should it not be

if User.count.zero+1? rais “cant delete last user” end

Thank you

_file_16_pragsmall
21 Dec 2007, 10:29
Rander de Paula Castro (2 posts)

Hi,

I’m doing the depot aplication tutorial, and the page 91, on the Iteration B3 I can’t use the number_to_currency helper. When I run the aplication, the folow message is show for me: NoMethodError: undefined method `number_to_currency’. My rails version is 1.2.5 and ruby version is 1.8.5. Thanks

_file_16_pragsmall
21 Dec 2007, 10:30
Rander de Paula Castro (2 posts)

Everybody, I just solved this, thanks! I have updated gem. Thanks.

Generic-user-small
21 Dec 2007, 12:52
themurmish (1 post)

I am currently working on 9.3 Iteration D3: Highlighting Changes: I am sure someone else must have had this problem before but I can’t find anything about it. The highlighting works for the first item added to the cart. It also works if the quantity of this first added item is being raised. But as soon as another item is being added the cart is not being updated anymore and of course no effect is being shown. If the page is reloaded the cart is updated during the reload but the JavaScript is still broken.

Generic-user-small
20 Jan 2008, 11:30
Graham Hunter (1 post)

Hi Guys, very new to rails and steadily making my way through this excellent book. However, got to page 68 (second addition) having just generated the controller admin, changed the admin_controller.rb file to add in the “scaffold :product” line, then started the WEBrick server and navigated to localhost:3000/admin

Received this error (below) Can anybody help me please? I’ve now gone through this several times but same outcome every time.

Regards, Graham.

NoMethodError in AdminController#index

undefined method `scaffold’ for AdminController:Class

RAILS_ROOT: D:/Work/depot Application Trace | Framework Trace | Full Trace

app/controllers/admin_controller.rb:10

C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activesupport-2.0.2/lib/active_support/dependencies.rb:203:in load_without_new_constant_marking' C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activesupport-2.0.2/lib/active_support/dependencies.rb:203:in load_file’ C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activesupport-2.0.2/lib/active_support/dependencies.rb:342:in new_constants_in' C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activesupport-2.0.2/lib/active_support/dependencies.rb:202:in load_file’ C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activesupport-2.0.2/lib/active_support/dependencies.rb:94:in require_or_load' C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activesupport-2.0.2/lib/active_support/dependencies.rb:248:in load_missing_constant’ C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activesupport-2.0.2/lib/active_support/dependencies.rb:453:in const_missing' C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activesupport-2.0.2/lib/active_support/dependencies.rb:465:in const_missing’ C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activesupport-2.0.2/lib/active_support/inflector.rb:257:in constantize' C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activesupport-2.0.2/lib/active_support/core_ext/string/inflections.rb:148:in constantize’ C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/routing.rb:1426:in recognize' C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/dispatcher.rb:170:in handle_request’ C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/dispatcher.rb:115:in dispatch' C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/dispatcher.rb:126:in dispatch_cgi’ C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/dispatcher.rb:9:in dispatch' C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.2-x86-mswin32/lib/mongrel/rails.rb:76:in process’ C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.2-x86-mswin32/lib/mongrel/rails.rb:74:in synchronize' C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.2-x86-mswin32/lib/mongrel/rails.rb:74:in process’ C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.2-x86-mswin32/lib/mongrel.rb:159:in process_client' C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.2-x86-mswin32/lib/mongrel.rb:158:in each’ C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.2-x86-mswin32/lib/mongrel.rb:158:in process_client' C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.2-x86-mswin32/lib/mongrel.rb:285:in run’ C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.2-x86-mswin32/lib/mongrel.rb:285:in initialize' C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.2-x86-mswin32/lib/mongrel.rb:285:in new’ C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.2-x86-mswin32/lib/mongrel.rb:285:in run' C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.2-x86-mswin32/lib/mongrel.rb:268:in initialize’ C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.2-x86-mswin32/lib/mongrel.rb:268:in new' C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.2-x86-mswin32/lib/mongrel.rb:268:in run’ C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.2-x86-mswin32/lib/mongrel/configurator.rb:282:in run' C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.2-x86-mswin32/lib/mongrel/configurator.rb:281:in each’ C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.2-x86-mswin32/lib/mongrel/configurator.rb:281:in run' C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.2-x86-mswin32/bin/mongrel_rails:128:in run’ C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.2-x86-mswin32/lib/mongrel/command.rb:212:in run' C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.2-x86-mswin32/bin/mongrel_rails:281 C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activesupport-2.0.2/lib/active_support/dependencies.rb:489:in load’ C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activesupport-2.0.2/lib/active_support/dependencies.rb:489:in load' C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activesupport-2.0.2/lib/active_support/dependencies.rb:342:in new_constants_in’ C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activesupport-2.0.2/lib/active_support/dependencies.rb:489:in load' C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/rails-2.0.2/lib/commands/servers/mongrel.rb:64 C:/InstantRails/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in gem_original_require’ C:/InstantRails/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in require' C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activesupport-2.0.2/lib/active_support/dependencies.rb:496:in require’ C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activesupport-2.0.2/lib/active_support/dependencies.rb:342:in new_constants_in' C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activesupport-2.0.2/lib/active_support/dependencies.rb:496:in require’ C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/rails-2.0.2/lib/commands/server.rb:39 C:/InstantRails/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in gem_original_require' C:/InstantRails/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in require’ script/server:3

app/controllers/admin_controller.rb:10 C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activesupport-2.0.2/lib/active_support/dependencies.rb:203:in load_without_new_constant_marking' C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activesupport-2.0.2/lib/active_support/dependencies.rb:203:in load_file’ C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activesupport-2.0.2/lib/active_support/dependencies.rb:342:in new_constants_in' C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activesupport-2.0.2/lib/active_support/dependencies.rb:202:in load_file’ C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activesupport-2.0.2/lib/active_support/dependencies.rb:94:in require_or_load' C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activesupport-2.0.2/lib/active_support/dependencies.rb:248:in load_missing_constant’ C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activesupport-2.0.2/lib/active_support/dependencies.rb:453:in const_missing' C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activesupport-2.0.2/lib/active_support/dependencies.rb:465:in const_missing’ C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activesupport-2.0.2/lib/active_support/inflector.rb:257:in constantize' C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activesupport-2.0.2/lib/active_support/core_ext/string/inflections.rb:148:in constantize’ C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/routing.rb:1426:in recognize' C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/dispatcher.rb:170:in handle_request’ C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/dispatcher.rb:115:in dispatch' C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/dispatcher.rb:126:in dispatch_cgi’ C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/dispatcher.rb:9:in dispatch' C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.2-x86-mswin32/lib/mongrel/rails.rb:76:in process’ C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.2-x86-mswin32/lib/mongrel/rails.rb:74:in synchronize' C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.2-x86-mswin32/lib/mongrel/rails.rb:74:in process’ C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.2-x86-mswin32/lib/mongrel.rb:159:in process_client' C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.2-x86-mswin32/lib/mongrel.rb:158:in each’ C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.2-x86-mswin32/lib/mongrel.rb:158:in process_client' C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.2-x86-mswin32/lib/mongrel.rb:285:in run’ C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.2-x86-mswin32/lib/mongrel.rb:285:in initialize' C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.2-x86-mswin32/lib/mongrel.rb:285:in new’ C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.2-x86-mswin32/lib/mongrel.rb:285:in run' C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.2-x86-mswin32/lib/mongrel.rb:268:in initialize’ C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.2-x86-mswin32/lib/mongrel.rb:268:in new' C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.2-x86-mswin32/lib/mongrel.rb:268:in run’ C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.2-x86-mswin32/lib/mongrel/configurator.rb:282:in run' C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.2-x86-mswin32/lib/mongrel/configurator.rb:281:in each’ C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.2-x86-mswin32/lib/mongrel/configurator.rb:281:in run' C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.2-x86-mswin32/bin/mongrel_rails:128:in run’ C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.2-x86-mswin32/lib/mongrel/command.rb:212:in run' C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.2-x86-mswin32/bin/mongrel_rails:281 C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activesupport-2.0.2/lib/active_support/dependencies.rb:489:in load’ C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activesupport-2.0.2/lib/active_support/dependencies.rb:489:in load' C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activesupport-2.0.2/lib/active_support/dependencies.rb:342:in new_constants_in’ C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activesupport-2.0.2/lib/active_support/dependencies.rb:489:in load' C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/rails-2.0.2/lib/commands/servers/mongrel.rb:64 C:/InstantRails/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in gem_original_require’ C:/InstantRails/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in require' C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activesupport-2.0.2/lib/active_support/dependencies.rb:496:in require’ C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activesupport-2.0.2/lib/active_support/dependencies.rb:342:in new_constants_in' C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activesupport-2.0.2/lib/active_support/dependencies.rb:496:in require’ C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/rails-2.0.2/lib/commands/server.rb:39 C:/InstantRails/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in gem_original_require' C:/InstantRails/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in require’ script/server:3

Request

Parameters:

None

Show session dump


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

Response

Headers:

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

12685522_100_pragsmall
21 Jan 2008, 03:38
bryon mayo (5 posts)

Graham, I’ve been going through this book today for the first time as well and ran across this error. It appears that rails 2.0 does not directly allow this functionality any more (or rather does it in a different way). What I’ve done is gone back to instantrails and downloaded version 1.7 instead so that I’m using the same version of rails as the book. Hope this helps

Generic-user-small
28 Jan 2008, 13:27
Kevin (2 posts)

I keep getting:

NameError in StoreController#save_order

uninitialized constant Order::LineItem

I am using the PDF version of the book to do iteration E1 here are the relevant files:

Order

class Order < ActiveRecord::Base
  has_many :line_items
  PAYMENT_TYPES = [
  # Displayed          stored in db
  [ "Check" ,          "check" ],
  [ "Credit card" ,    "cc"   ],
  [ "Purchase order" , "po" ]
  ]
  validates_presence_of :name, :address, :email, :pay_type
  validates_inclusion_of :pay_type, :in => PAYMENT_TYPES.map {|disp, value| value}
  
  
 
  def add_line_items_from_cart(cart)
    cart.items.each do |item|
      li=LineItem.from_cart_item(item)
      line_items<<li
    end
  end
end

LineItem

class LineItem < ActiveRecord::Base
  belongs_to :order
  belongs_to :product
 
  
 
  
  def self.from_cart_item(cart_item)
    li = self.new
    li.product     = cart_item.product
    li.quantity    = cart_item.quantity
    li.total_price = cart_item.price
    li
  end    
  
end

Store Controller

class StoreController < ApplicationController
  
  def index
    @products=Product.find_products_for_sale
    @cart=find_cart
  end
  
  def add_to_cart #add product to the the cart.      
    begin
      product = Product.find(params[:id])
    rescue ActiveRecord::RecordNotFound
      logger.error("Attempt to access invalid product #{params[:id]}")
      flash[:notice] = "Invalid product"
      redirect_to :action => :index
    else
      @cart = find_cart
      @current_item = @cart.add_product(product)
      redirect_to_index unless request.xhr?
    end
  end
  def remove_item #remove product from the the cart.      
    begin
      product = Product.find(params[:id])
    rescue ActiveRecord::RecordNotFound
      logger.error("Attempt to access invalid product #{params[:id]}")
      flash[:notice] = "no item in cart."
      redirect_to :action => :index
    else
      @cart = find_cart
      @current_item = @cart.remove_product(product)
      redirect_to_index unless request.xhr?
    end
  end
  
  def redirect_to_index(msg = nil)
    flash[:notice] = msg if msg
    redirect_to :action => :index
  end
  
  def empty_cart
    session[:cart]=nil
    redirect_to_index
  end
  
  def checkout
    @cart = find_cart
    if @cart.items.empty?
      redirect_to_index("Your cart is empty" )
    else
      @order = Order.new
    end
  end
  
  def save_order
    @cart=find_cart
    @order=Order.new(params[:order])
    @order.add_line_items_from_cart(@cart)
    if @order.save #This is an activerecord method all models will have it.
      session[:cart] = nil #clear the cart before redirecting the user to the index.
      redirect_to_index("Thank you for your order" )
    else
      render :action => :checkout
    end
    
  end
  
  private
  
  def find_cart # if there's no cart in the session  add a new one   
    unless session[:cart]          
      session[:cart]=Cart.new
    end
    session[:cart]  # return existing or new cart
  end
end

Rails version is 1.2.3

Generic-user-small
30 Jan 2008, 15:52
Wiley Thomas (2 posts)

Hi - I’m following the PDF version (2007-11-08) and get an error when modifying the AdminController on page 76. I’m running on mac OS X 10.5.1 using the standard ruby environment.

class AdminController < ApplicationController scaffold :product end

My browser returns:

NoMethodError in AdminController#index

undefined method `scaffold’ for AdminController:Class

An earlier post referenced some “fixees” for the mac standard rails environment but I couldn’t find any. Can you help?

Thm_0888_pragsmall
05 Feb 2008, 05:18
Simon Krollpfeifer (7 posts)

@ Wiley Check my post (scroll down) in this topic: http://forums.pragprog.com/forums/22/topics/184

Generic-user-small
09 Apr 2008, 11:09
Joshua Cooper (3 posts)

Has anyone found a solution to the ` NoMethodError in AdminController#index

undefined method `scaffold’ for AdminController:Class

RAILS_ROOT: C:/InstantRails-2.0-win/rails_apps/depot Application Trace | Framework Trace | Full Trace

app/controllers/admin_controller.rb:2

C:/InstantRails-2.0-win/ruby/lib/ruby/gems/1.8/gems/activesupport-2.0.2/lib/active_support/dependencies.rb:203:in load_without_new_constant_marking' C:/InstantRails-2.0-win/ruby/lib/ruby/gems/1.8/gems/activesupport-2.0.2/lib/active_support/dependencies.rb:203:in load_file’ C:/InstantRails-2.0-win/ruby/lib/ruby/gems/1.8/gems/activesupport-2.0.2/lib/active_support/dependencies.rb:342:in new_constants_in' C:/InstantRails-2.0-win/ruby/lib/ruby/gems/1.8/gems/activesupport-2.0.2/lib/active_support/dependencies.rb:202:in load_file’ C:/InstantRails-2.0-win/ruby/lib/ruby/gems/1.8/gems/activesupport-2.0.2/lib/active_support/dependencies.rb:94:in require_or_load' C:/InstantRails-2.0-win/ruby/lib/ruby/gems/1.8/gems/activesupport-2.0.2/lib/active_support/dependencies.rb:248:in load_missing_constant’ C:/InstantRails-2.0-win/ruby/lib/ruby/gems/1.8/gems/activesupport-2.0.2/lib/active_support/dependencies.rb:453:in const_missing' C:/InstantRails-2.0-win/ruby/lib/ruby/gems/1.8/gems/activesupport-2.0.2/lib/active_support/dependencies.rb:465:in const_missing’ C:/InstantRails-2.0-win/ruby/lib/ruby/gems/1.8/gems/activesupport-2.0.2/lib/active_support/inflector.rb:257:in constantize' C:/InstantRails-2.0-win/ruby/lib/ruby/gems/1.8/gems/activesupport-2.0.2/lib/active_support/core_ext/string/inflections.rb:148:in constantize’ C:/InstantRails-2.0-win/ruby/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/routing.rb:1426:in recognize' C:/InstantRails-2.0-win/ruby/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/dispatcher.rb:170:in handle_request’ C:/InstantRails-2.0-win/ruby/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/dispatcher.rb:115:in dispatch' C:/InstantRails-2.0-win/ruby/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/dispatcher.rb:126:in dispatch_cgi’ C:/InstantRails-2.0-win/ruby/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/dispatcher.rb:9:in dispatch' C:/InstantRails-2.0-win/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.2-x86-mswin32/lib/mongrel/rails.rb:76:in process’ C:/InstantRails-2.0-win/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.2-x86-mswin32/lib/mongrel/rails.rb:74:in synchronize' C:/InstantRails-2.0-win/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.2-x86-mswin32/lib/mongrel/rails.rb:74:in process’ C:/InstantRails-2.0-win/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.2-x86-mswin32/lib/mongrel.rb:159:in process_client' C:/InstantRails-2.0-win/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.2-x86-mswin32/lib/mongrel.rb:158:in each’ C:/InstantRails-2.0-win/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.2-x86-mswin32/lib/mongrel.rb:158:in process_client' C:/InstantRails-2.0-win/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.2-x86-mswin32/lib/mongrel.rb:285:in run’ C:/InstantRails-2.0-win/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.2-x86-mswin32/lib/mongrel.rb:285:in initialize' C:/InstantRails-2.0-win/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.2-x86-mswin32/lib/mongrel.rb:285:in new’ C:/InstantRails-2.0-win/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.2-x86-mswin32/lib/mongrel.rb:285:in run' C:/InstantRails-2.0-win/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.2-x86-mswin32/lib/mongrel.rb:268:in initialize’ C:/InstantRails-2.0-win/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.2-x86-mswin32/lib/mongrel.rb:268:in new' C:/InstantRails-2.0-win/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.2-x86-mswin32/lib/mongrel.rb:268:in run’ C:/InstantRails-2.0-win/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.2-x86-mswin32/lib/mongrel/configurator.rb:282:in run' C:/InstantRails-2.0-win/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.2-x86-mswin32/lib/mongrel/configurator.rb:281:in each’ C:/InstantRails-2.0-win/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.2-x86-mswin32/lib/mongrel/configurator.rb:281:in run' C:/InstantRails-2.0-win/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.2-x86-mswin32/bin/mongrel_rails:128:in run’ C:/InstantRails-2.0-win/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.2-x86-mswin32/lib/mongrel/command.rb:212:in run' C:/InstantRails-2.0-win/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.2-x86-mswin32/bin/mongrel_rails:281 C:/InstantRails-2.0-win/ruby/lib/ruby/gems/1.8/gems/activesupport-2.0.2/lib/active_support/dependencies.rb:489:in load’ C:/InstantRails-2.0-win/ruby/lib/ruby/gems/1.8/gems/activesupport-2.0.2/lib/active_support/dependencies.rb:489:in load' C:/InstantRails-2.0-win/ruby/lib/ruby/gems/1.8/gems/activesupport-2.0.2/lib/active_support/dependencies.rb:342:in new_constants_in’ C:/InstantRails-2.0-win/ruby/lib/ruby/gems/1.8/gems/activesupport-2.0.2/lib/active_support/dependencies.rb:489:in load' C:/InstantRails-2.0-win/ruby/lib/ruby/gems/1.8/gems/rails-2.0.2/lib/commands/servers/mongrel.rb:64 C:/InstantRails-2.0-win/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in gem_original_require’ C:/InstantRails-2.0-win/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in require' C:/InstantRails-2.0-win/ruby/lib/ruby/gems/1.8/gems/activesupport-2.0.2/lib/active_support/dependencies.rb:496:in require’ C:/InstantRails-2.0-win/ruby/lib/ruby/gems/1.8/gems/activesupport-2.0.2/lib/active_support/dependencies.rb:342:in new_constants_in' C:/InstantRails-2.0-win/ruby/lib/ruby/gems/1.8/gems/activesupport-2.0.2/lib/active_support/dependencies.rb:496:in require’ C:/InstantRails-2.0-win/ruby/lib/ruby/gems/1.8/gems/rails-2.0.2/lib/commands/server.rb:39 C:/InstantRails-2.0-win/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in gem_original_require' C:/InstantRails-2.0-win/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in require’ script/server:3

app/controllers/admin_controller.rb:2 C:/InstantRails-2.0-win/ruby/lib/ruby/gems/1.8/gems/activesupport-2.0.2/lib/active_support/dependencies.rb:203:in load_without_new_constant_marking' C:/InstantRails-2.0-win/ruby/lib/ruby/gems/1.8/gems/activesupport-2.0.2/lib/active_support/dependencies.rb:203:in load_file’ C:/InstantRails-2.0-win/ruby/lib/ruby/gems/1.8/gems/activesupport-2.0.2/lib/active_support/dependencies.rb:342:in new_constants_in' C:/InstantRails-2.0-win/ruby/lib/ruby/gems/1.8/gems/activesupport-2.0.2/lib/active_support/dependencies.rb:202:in load_file’ C:/InstantRails-2.0-win/ruby/lib/ruby/gems/1.8/gems/activesupport-2.0.2/lib/active_support/dependencies.rb:94:in require_or_load' C:/InstantRails-2.0-win/ruby/lib/ruby/gems/1.8/gems/activesupport-2.0.2/lib/active_support/dependencies.rb:248:in load_missing_constant’ C:/InstantRails-2.0-win/ruby/lib/ruby/gems/1.8/gems/activesupport-2.0.2/lib/active_support/dependencies.rb:453:in const_missing' C:/InstantRails-2.0-win/ruby/lib/ruby/gems/1.8/gems/activesupport-2.0.2/lib/active_support/dependencies.rb:465:in const_missing’ C:/InstantRails-2.0-win/ruby/lib/ruby/gems/1.8/gems/activesupport-2.0.2/lib/active_support/inflector.rb:257:in constantize' C:/InstantRails-2.0-win/ruby/lib/ruby/gems/1.8/gems/activesupport-2.0.2/lib/active_support/core_ext/string/inflections.rb:148:in constantize’ C:/InstantRails-2.0-win/ruby/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/routing.rb:1426:in recognize' C:/InstantRails-2.0-win/ruby/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/dispatcher.rb:170:in handle_request’ C:/InstantRails-2.0-win/ruby/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/dispatcher.rb:115:in dispatch' C:/InstantRails-2.0-win/ruby/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/dispatcher.rb:126:in dispatch_cgi’ C:/InstantRails-2.0-win/ruby/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/dispatcher.rb:9:in dispatch' C:/InstantRails-2.0-win/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.2-x86-mswin32/lib/mongrel/rails.rb:76:in process’ C:/InstantRails-2.0-win/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.2-x86-mswin32/lib/mongrel/rails.rb:74:in synchronize' C:/InstantRails-2.0-win/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.2-x86-mswin32/lib/mongrel/rails.rb:74:in process’ C:/InstantRails-2.0-win/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.2-x86-mswin32/lib/mongrel.rb:159:in process_client' C:/InstantRails-2.0-win/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.2-x86-mswin32/lib/mongrel.rb:158:in each’ C:/InstantRails-2.0-win/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.2-x86-mswin32/lib/mongrel.rb:158:in process_client' C:/InstantRails-2.0-win/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.2-x86-mswin32/lib/mongrel.rb:285:in run’ C:/InstantRails-2.0-win/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.2-x86-mswin32/lib/mongrel.rb:285:in initialize' C:/InstantRails-2.0-win/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.2-x86-mswin32/lib/mongrel.rb:285:in new’ C:/InstantRails-2.0-win/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.2-x86-mswin32/lib/mongrel.rb:285:in run' C:/InstantRails-2.0-win/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.2-x86-mswin32/lib/mongrel.rb:268:in initialize’ C:/InstantRails-2.0-win/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.2-x86-mswin32/lib/mongrel.rb:268:in new' C:/InstantRails-2.0-win/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.2-x86-mswin32/lib/mongrel.rb:268:in run’ C:/InstantRails-2.0-win/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.2-x86-mswin32/lib/mongrel/configurator.rb:282:in run' C:/InstantRails-2.0-win/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.2-x86-mswin32/lib/mongrel/configurator.rb:281:in each’ C:/InstantRails-2.0-win/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.2-x86-mswin32/lib/mongrel/configurator.rb:281:in run' C:/InstantRails-2.0-win/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.2-x86-mswin32/bin/mongrel_rails:128:in run’ C:/InstantRails-2.0-win/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.2-x86-mswin32/lib/mongrel/command.rb:212:in run' C:/InstantRails-2.0-win/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.2-x86-mswin32/bin/mongrel_rails:281 C:/InstantRails-2.0-win/ruby/lib/ruby/gems/1.8/gems/activesupport-2.0.2/lib/active_support/dependencies.rb:489:in load’ C:/InstantRails-2.0-win/ruby/lib/ruby/gems/1.8/gems/activesupport-2.0.2/lib/active_support/dependencies.rb:489:in load' C:/InstantRails-2.0-win/ruby/lib/ruby/gems/1.8/gems/activesupport-2.0.2/lib/active_support/dependencies.rb:342:in new_constants_in’ C:/InstantRails-2.0-win/ruby/lib/ruby/gems/1.8/gems/activesupport-2.0.2/lib/active_support/dependencies.rb:489:in load' C:/InstantRails-2.0-win/ruby/lib/ruby/gems/1.8/gems/rails-2.0.2/lib/commands/servers/mongrel.rb:64 C:/InstantRails-2.0-win/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in gem_original_require’ C:/InstantRails-2.0-win/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in require' C:/InstantRails-2.0-win/ruby/lib/ruby/gems/1.8/gems/activesupport-2.0.2/lib/active_support/dependencies.rb:496:in require’ C:/InstantRails-2.0-win/ruby/lib/ruby/gems/1.8/gems/activesupport-2.0.2/lib/active_support/dependencies.rb:342:in new_constants_in' C:/InstantRails-2.0-win/ruby/lib/ruby/gems/1.8/gems/activesupport-2.0.2/lib/active_support/dependencies.rb:496:in require’ C:/InstantRails-2.0-win/ruby/lib/ruby/gems/1.8/gems/rails-2.0.2/lib/commands/server.rb:39 C:/InstantRails-2.0-win/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in gem_original_require' C:/InstantRails-2.0-win/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in require’ script/server:3

Request

Parameters:

None

Show session dump


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

Response

Headers:

{“cookie”=>[], “Cache-Control”=>”no-cache”} `

Problem? please help.

Generic-user-small
20 Jun 2008, 19:06
Eric H (2 posts)

Was there any resolution to this problem? http://forums.pragprog.com/forums/22/topics/10?page=7#posts-1390

Generic-user-small
20 Jun 2008, 19:06
Eric H (2 posts)

Was there any resolution to this problem? http://forums.pragprog.com/forums/22/topics/10?page=7#posts-1390

Generic-user-small
01 Nov 2008, 06:44
Hayden Hancock (3 posts)

I am only on page 77 of the Beta book and have run into an error on rake db:migrate.

Ruby version: 1.8.6 Rails version: 2.1.2 Gem version: 1.3.1

rake aborted! no such file to load -- sqlite3

I’ve installed rake using the command: gem install rake I’ve also tried deleting the “Depot” application and restarting but continue to get the same error.

Generic-user-small
06 Nov 2008, 06:36
Joe Sak (2 posts)

I just got to p 124 in the 2nd Edition.

I got the highlighting of the current item working. Now, for no reason, when I click add to cart, it adds double. It used to increment properly but now it’s incrementing double.

So I click Add to Cart and it says 2x Book Title Price I click Add to Cart again and it says 4x Book Title Price

Can anyone help me figure out why this is happening?

Generic-user-small
06 Nov 2008, 06:57
Joe Sak (2 posts)

Just found out:

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
  	  	@cart.add_product(product)
  	  	@current_item = @cart.add_product(product)
  	  	
  	end
  end

I had the add_product method running twice. smack forehead

Generic-user-small
13 Nov 2008, 16:13
Andreas Boman (1 post)

I have v2 of the book; doing depot in rails 1.2.6 and I’m stuck at iteration D3: Highlighting Changes.

The javascript cart update added in D2 works fine. When I add the D3 stuff the cart stops updating until a page reload (and no effect is visible).

As you may notice, I moved on and tried D4, also with no luck (similar error). I have spent a day googling and reading various threads on lists and forums to no avail. If I comment the visual_effect lines out in add_to_cart.rjs the app up to iteration D2 works as expected. Any help would be very welcome.

These should be the relevant log and code snippets:

@log@

Processing StoreController#add_to_cart (for 127.0.0.1 at 2008-11-13 10:48:12) [POST]
  Session ID: d9989c77d2d4dbe5a15a970c0e8de41b
  Parameters: {"commit"=>"Add to Cart", "action"=>"add_to_cart", "id"=>"6", "controller"=>"store"}
  Product Columns (0.003199)   SHOW FIELDS FROM products
  Product Load (0.001346)   SELECT * FROM products WHERE (products.`id` = 6) 
Rendering store/add_to_cart
Rendered store/_cart_item (0.00187)
Rendered store/_cart_item (0.00040)
Rendered store/_cart_item (0.00037)
Rendered store/_cart (0.00730)


ActionView::TemplateError (undefined method `[]' for #<Enumerable::Enumerator:0x7f61e8a06008>) on line #5 of app/views/store/add_to_cart.rjs:
2: 
3: #page[:cart].visual_effect :blind_down if @cart.total_items == 1
4: 
5: page[:current_item].visual_effect :highlight

    $HOME/.gem/ruby/1.8/gems/activesupport-1.4.4/lib/active_support/core_ext/string/access.rb:43:in `first'
    $HOME/.gem/ruby/1.8/gems/activesupport-1.4.4/lib/active_support/inflector.rb:144:in `camelize'
    $HOME/.gem/ruby/1.8/gems/activesupport-1.4.4/lib/active_support/core_ext/string/inflections.rb:49:in `camelize'
    $HOME/.gem/ruby/1.8/gems/actionpack-1.13.6/lib/action_view/helpers/prototype_helper.rb:719:in `method_missing'
    $HOME/src/rails/depot/app/views/store/add_to_cart.rjs:5:in `_run_rjs_47app47views47store47add_to_cart46rjs'
    $HOME/.gem/ruby/1.8/gems/actionpack-1.13.6/lib/action_view/helpers/prototype_helper.rb:329:in `instance_exec'
    $HOME/.gem/ruby/1.8/gems/actionpack-1.13.6/lib/action_view/helpers/prototype_helper.rb:329:in `initialize'
    $HOME/.gem/ruby/1.8/gems/actionpack-1.13.6/lib/action_view/helpers/prototype_helper.rb:641:in `new'
    $HOME/.gem/ruby/1.8/gems/actionpack-1.13.6/lib/action_view/helpers/prototype_helper.rb:641:in `update_page'
    $HOME/src/rails/depot/app/views/store/add_to_cart.rjs:0:in `_run_rjs_47app47views47store47add_to_cart46rjs'
    $HOME/.gem/ruby/1.8/gems/actionpack-1.13.6/lib/action_view/base.rb:325:in `send'
    $HOME/.gem/ruby/1.8/gems/actionpack-1.13.6/lib/action_view/base.rb:325:in `compile_and_render_template'
    $HOME/.gem/ruby/1.8/gems/actionpack-1.13.6/lib/action_view/base.rb:301:in `render_template'
    $HOME/.gem/ruby/1.8/gems/actionpack-1.13.6/lib/action_view/base.rb:260:in `render_file'
    $HOME/.gem/ruby/1.8/gems/actionpack-1.13.6/lib/action_controller/base.rb:812:in `render_file'
    $HOME/.gem/ruby/1.8/gems/actionpack-1.13.6/lib/action_controller/base.rb:717:in `render_with_no_layout'
    $HOME/.gem/ruby/1.8/gems/actionpack-1.13.6/lib/action_controller/layout.rb:256:in `render_without_benchmark'
    $HOME/.gem/ruby/1.8/gems/actionpack-1.13.6/lib/action_controller/benchmarking.rb:50:in `render'
    /usr/lib/ruby/1.8/benchmark.rb:293:in `measure'
    $HOME/.gem/ruby/1.8/gems/actionpack-1.13.6/lib/action_controller/benchmarking.rb:50:in `render'
    $HOME/.gem/ruby/1.8/gems/actionpack-1.13.6/lib/action_controller/base.rb:1102:in `perform_action_without_filters'
    $HOME/.gem/ruby/1.8/gems/actionpack-1.13.6/lib/action_controller/filters.rb:696:in `call_filters'
    $HOME/.gem/ruby/1.8/gems/actionpack-1.13.6/lib/action_controller/filters.rb:688:in `perform_action_without_benchmark'
    $HOME/.gem/ruby/1.8/gems/actionpack-1.13.6/lib/action_controller/benchmarking.rb:66:in `perform_action_without_rescue'
    /usr/lib/ruby/1.8/benchmark.rb:293:in `measure'
    $HOME/.gem/ruby/1.8/gems/actionpack-1.13.6/lib/action_controller/benchmarking.rb:66:in `perform_action_without_rescue'
    $HOME/.gem/ruby/1.8/gems/actionpack-1.13.6/lib/action_controller/rescue.rb:83:in `perform_action'
    $HOME/.gem/ruby/1.8/gems/actionpack-1.13.6/lib/action_controller/base.rb:435:in `send'
    $HOME/.gem/ruby/1.8/gems/actionpack-1.13.6/lib/action_controller/base.rb:435:in `process_without_filters'
    $HOME/.gem/ruby/1.8/gems/actionpack-1.13.6/lib/action_controller/filters.rb:684:in `process_without_session_management_support'
    $HOME/.gem/ruby/1.8/gems/actionpack-1.13.6/lib/action_controller/session_management.rb:114:in `process'
    $HOME/.gem/ruby/1.8/gems/actionpack-1.13.6/lib/action_controller/base.rb:334:in `process'
    $HOME/.gem/ruby/1.8/gems/rails-1.2.6/lib/dispatcher.rb:41:in `dispatch'
    /usr/lib/ruby/gems/1.8/gems/mongrel-1.1.5/lib/mongrel/rails.rb:76:in `process'
    /usr/lib/ruby/gems/1.8/gems/mongrel-1.1.5/lib/mongrel/rails.rb:74:in `synchronize'
    /usr/lib/ruby/gems/1.8/gems/mongrel-1.1.5/lib/mongrel/rails.rb:74:in `process'
    /usr/lib/ruby/gems/1.8/gems/mongrel-1.1.5/lib/mongrel.rb:159:in `process_client'
    /usr/lib/ruby/gems/1.8/gems/mongrel-1.1.5/lib/mongrel.rb:158:in `each'
    /usr/lib/ruby/gems/1.8/gems/mongrel-1.1.5/lib/mongrel.rb:158:in `process_client'
    /usr/lib/ruby/gems/1.8/gems/mongrel-1.1.5/lib/mongrel.rb:285:in `run'
    /usr/lib/ruby/gems/1.8/gems/mongrel-1.1.5/lib/mongrel.rb:285:in `initialize'
    /usr/lib/ruby/gems/1.8/gems/mongrel-1.1.5/lib/mongrel.rb:285:in `new'
    /usr/lib/ruby/gems/1.8/gems/mongrel-1.1.5/lib/mongrel.rb:285:in `run'
    /usr/lib/ruby/gems/1.8/gems/mongrel-1.1.5/lib/mongrel.rb:268:in `initialize'
    /usr/lib/ruby/gems/1.8/gems/mongrel-1.1.5/lib/mongrel.rb:268:in `new'
    /usr/lib/ruby/gems/1.8/gems/mongrel-1.1.5/lib/mongrel.rb:268:in `run'
    /usr/lib/ruby/gems/1.8/gems/mongrel-1.1.5/lib/mongrel/configurator.rb:282:in `run'
    /usr/lib/ruby/gems/1.8/gems/mongrel-1.1.5/lib/mongrel/configurator.rb:281:in `each'
    /usr/lib/ruby/gems/1.8/gems/mongrel-1.1.5/lib/mongrel/configurator.rb:281:in `run'
    /usr/lib/ruby/gems/1.8/gems/mongrel-1.1.5/bin/mongrel_rails:128:in `run'
    /usr/lib/ruby/gems/1.8/gems/mongrel-1.1.5/lib/mongrel/command.rb:212:in `run'
    /usr/lib/ruby/gems/1.8/gems/mongrel-1.1.5/bin/mongrel_rails:281
    $HOME/.gem/ruby/1.8/gems/activesupport-1.4.4/lib/active_support/dependencies.rb:488:in `load'
    $HOME/.gem/ruby/1.8/gems/activesupport-1.4.4/lib/active_support/dependencies.rb:488:in `load'
    $HOME/.gem/ruby/1.8/gems/activesupport-1.4.4/lib/active_support/dependencies.rb:342:in `new_constants_in'
    $HOME/.gem/ruby/1.8/gems/activesupport-1.4.4/lib/active_support/dependencies.rb:488:in `load'
    $HOME/.gem/ruby/1.8/gems/rails-1.2.6/lib/commands/servers/mongrel.rb:60
    /usr/local/lib/site_ruby/1.8/rubygems/custom_require.rb:27:in `gem_original_require'
    /usr/local/lib/site_ruby/1.8/rubygems/custom_require.rb:27:in `require'
    $HOME/.gem/ruby/1.8/gems/activesupport-1.4.4/lib/active_support/dependencies.rb:495:in `require'
    $HOME/.gem/ruby/1.8/gems/activesupport-1.4.4/lib/active_support/dependencies.rb:342:in `new_constants_in'
    $HOME/.gem/ruby/1.8/gems/activesupport-1.4.4/lib/active_support/dependencies.rb:495:in `require'
    $HOME/.gem/ruby/1.8/gems/rails-1.2.6/lib/commands/server.rb:39
    /usr/local/lib/site_ruby/1.8/rubygems/custom_require.rb:27:in `gem_original_require'
    /usr/local/lib/site_ruby/1.8/rubygems/custom_require.rb:27:in `require' 
script/server:3

Rendering $HOME/.gem/ruby/1.8/gems/actionpack-1.13.6/lib/action_controller/templates/rescues/layout.rhtml (500 Internal Error)

@cart.rb@

  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

@store_controller.rb@

  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)
    end
  end

@_cart_item.rhtml@

<% if cart_item == @current_item %>
  <tr id="current_item">
<% else %>
  <tr>
<% end %>
    <td><%= cart_item.quantity %>&times;</td>
    <td><%=h cart_item.title %></td>
    <td class="item-price"><%= number_to_currency(cart_item.price) %></td>
  </tr>

@add_to_cart.rjs@

page.replace_html("cart", :partial => "cart", :object => @cart)

#page[:cart].visual_effect :blind_down if @cart.total_items == 1

page[:current_item].visual_effect :highlight
Small_potato_pragsmall
30 Nov 2008, 06:18
choonsiong (1 post)

I have the same problem as Andreas… any helps appreciate. :-)

Generic-user-small
27 Jan 2009, 00:43
Michael Curry (1 post)

Just picked up this book and thread - I had the same problem and solved it by changing the add_to_cart.rjs:

for some reason the page[:IDselector] does not work for me…

#also enclosing “ in hex values of start and endcolor is needed (ex. “ ‘ #value ‘ “ )

page.visual_effect :highlight, :current_item, :startcolor => “‘#CCCCCC’”, :endcolor => “‘#000000’”

Generic-user-small
11 Feb 2009, 18:01
yury.su (1 post)

Hello everybody :)

If you are working on Mac, no need to install an old version of Rails! Please use Locomotive 2.0.8
While using Locomotive, all run smoothly with DEPOT.

for info: http://www.tuaw.com/2007/03/15/locomotive-ruby-on-rails-on-mac/ http://arstechnica.com/apple/news/2007/03/get-rolling-with-ruby-on-rails-using-locomotive.ars

for downloading: http://mac.softpedia.com/get/Development/Libraries/Locomotive.shtml

Generic-user-small
22 Jul 2009, 05:28
Ryan (1 post)

Greetings, I am having a problem with the blind down working with add_to_cart after I have emptied the cart once, and then added another item back to the cart.

-The blind down works fine when initially entering the store page and adding an item to the cart, and the blind up effect works when the empty cart button is pressed. However, after emptying the cart and then adding a new item to the cart, the blind down does not occur so that the user can see the cart item. I’ve tried setting the cart to nil and just clearing all items out of the cart. I’m new at this and have been banging on this for hours, any ideas how to get the blind down occur after the cart is emptied? Please let me know if more info is needed…

thank you Ryan

Rails v2.2.2 AWDWR 3rd Edition

Generic-user-small
09 Sep 2009, 01:46
ron campbell (22 posts)

On Page 107 in the PDF, Third Edition. I’m having an issue with the Depot application Cart Sessions.

Despite trying to set my version to run in 2.2.2 along with the book, I am running in 2.3.4, which would be fine, if the update notes were a little more specific

I found the right lines in the config/initializers/session_store.rb, but am not siure which to uncomment. so far, I have tried

(create the session table with “rake db:sessions:create”)

ActionController::Base.session_store = :active_record_store config.action_controller.session = { :session_key => ‘_depot_session’ , :secret => ‘f914e9b1bbdb829688de8512f…9b1810a4e238a61dfd922dc9dd62521’ }

and also tried comment out the secret line.

because on the next page it tells that the secret function is no longer needed or supported, but it shuts the server down on initilization.

Generic-user-small
26 Oct 2009, 03:17
Kansas Boyett (2 posts)

Hi, I am an idiot and made the stupid decision to install ruby 1.9 from 1.8.something in the middle of working through the depot project. I’ve been unable to get what I’ve done to work since then. My rails version hasn’t changed (version 2.3.4).

I have downloaded the code examples, but I haven’t been able to get them to work either. Any help on this subject would be greatly appreciated.

You must be logged in to comment