Posts by Steve Castaneda

21 Feb 2011, 03:33
Generic-user-small

Steve Castaneda (11 posts)

(from Agile Web Development with Rails 3.2 > Using join - why the argument?)

In: depot_c/test/unit/product_test.rb (early in the book - sorry reading on iPad)

I noticed that on the test “product is not valid without a unique title”, the assertion at the end “assert_equal” uses an argument on the join when comparing the error message.

For this particular test, we know what the error should be and there should only be one. Would it be safe to say that the argument that’s passed on the join is pointless (’; ‘)?

product.errors[:title].join(‘; ‘)

as opposed to just:

product.errors[:title].join

From what I understand, the argument is used to combine multiple values of an array (so if you put a dash the resulting string would list the values separated by a dash), but in this case we know that the array in the errors hash for :title will only have one value.

PS. This is my attempt to completely understand everything as I read. I really want to get it this time around!

PSS. Is this what people describe when they talk about “elegant” coding or is this just a simple refactor?

21 Feb 2011, 03:43
Generic-user-small

Steve Castaneda (11 posts)

(from Agile Web Development with Rails 3.2 > Test::Unit and BDD)

Doesn’t the 37 signals team using Test::Unit for testing for their suite of products? I swear I read a comment by DHH on that fairly recently.

22 Feb 2011, 01:34
Generic-user-small

Steve Castaneda (11 posts)

(from Agile Web Development with Rails 3.2 > Modify the shop controller to display product by type)

I think the first thing you’ll want to do is revise that route.

match ‘shop’ => ‘shop#index’

This will allow you to reference root_path/shop, which will point to your index method in the shop controller.

Are you trying to reference a shop by providing a product_type? So a shop has_many product_types?

27 Feb 2011, 17:16
Generic-user-small

Steve Castaneda (11 posts)

(from Agile Web Development with Rails 3.2 > Starting from depot_o)

Learning to use git while developing is very crucial, in my opinion. I would highly recommend you work out the problems you have so that you can use it while coding.

I make tons of coding mistakes too, and love to try new things and git is an invaluable tool here for not messing up my work that I know is properly functioning.

02 Mar 2011, 15:55
Generic-user-small

Steve Castaneda (11 posts)

(from Agile Web Development with Rails 3.2 > Problem with Ajax (F2))

I was having this issue at one point, and putting script tags in the js file did the trick. You can also try removing the :format => :js, and moving that logic into the controller at the top:

respond_to :js, :html

Then in the particular method, in this case the “change” method:

def change
@variable = whatever

respond_with(@variable) do |format|
  format.html { redirect_to whereever_path }
  format.js
end

This should cause the file to render the JS file correctly, which should be named change.js.erb and in the same directory as the view you’re rendering.

Does that do the trick?

05 Mar 2011, 22:29
Generic-user-small

Steve Castaneda (11 posts)

(from Agile Web Development with Rails 3.2 > app/views/layouts/application.html.erb)

Can you please post the contents of your config/environments.rb file, please?

Edit: Actually, what view in particular are you trying to render? Post the contents of that controller method as well just in case.

07 Mar 2011, 16:57
Generic-user-small

Steve Castaneda (11 posts)

(from Agile Web Development with Rails 3.2 > Ajax Cart Works in Firefox and Safari but not in Chrome (F3))

Is there anything popping up in development.log when the error occurs?

23 Mar 2011, 13:45
Generic-user-small

Steve Castaneda (11 posts)

(from Agile Web Development with Rails 3.2 > Task E store_url)

How are you mapping the resources for :store in your routes.rb? The match parameter you added will do the trick, but I’m curious as to why it was mapping store_index vs just finding index at /store.

15 Apr 2011, 17:15
Generic-user-small

Steve Castaneda (11 posts)

(from Agile Web Development with Rails 3.2 > Mac Installation of RoR [Ruby on Rails])

Have you checked out brew?

http://bsdjedi.blogspot.com/2011/03/moving-over-from-macports-to-brew.html

I used Brew to install Postgresql for deployment to Heroku on my local machine a while back, so I’m sure it can handle a RoR installation.

11 Mar 2012, 10:26
Generic-user-small

Steve Castaneda (11 posts)

(from Programming Ruby 1.9 (3rd edition) > Virtual Attributes - Why no instance variable used?)

Under Objects and Attributes > Virtual Attributes, where we look at:

tut_classes/stock_stats/book_in_stock_7.rb

I’m curious as to why, in the price_in_cents method, a local variable is used for price instead of an instance variable?

I thought I understood that local variables were encapsulated inside a method, but in this case, price is being called when not being passed into the method.

See: Integer(price*100 + 0.5)

Can anyone help me understand why a local variable was used for price, instead of an instance variable?

13 Mar 2012, 19:23
Generic-user-small

Steve Castaneda (11 posts)

(from Programming Ruby 1.9 (3rd edition) > Virtual Attributes - Why no instance variable used?)

Ah, I see now. So is it likely to confuse a local variable with a method then (since the format is the same), or would it just be best practice to not use local variables at all? For example, say I created a method which took a parameter called price, forgetting that I already have an attr_accessor defined. Possible issue or would the local variable take precedence?

Thank you for the guidance, by the way.

11 posts