Generic-user-small Fora User 0 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 Fora User 0 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 Fora User 0 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 Fora User 0 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 Fora User 0 posts

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

 
Generic-user-small Fora User 0 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 Fora User 0 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 Fora User 0 posts

Man, do I love the revamp. Thumbs up!

 
Generic-user-small Fora User 0 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 Fora User 0 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 Fora User 0 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 Fora User 0 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 Fora User 0 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 Fora User 0 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 Fora User 0 posts

You might find these three links interesting:

 
Generic-user-small Fora User 0 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 Fora User 0 posts

Thanks Roderick – appreciate that ! Dave

 
Generic-user-small Fora User 0 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 Fora User 0 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 Fora User 0 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 Fora User 0 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 Fora User 0 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 Fora User 0 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 Fora User 0 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

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 Fora User 0 posts

1111111111111111

365 posts, 33 voices

Page: 1 2 3