05 Jan 2009, 14:33
Generic-user-small

Bharat Ruparel (146 posts)

Hello Ryan, A happy new year to you! I have gone through the screencasts a few times and now am working through the code starting with Episode 1. Here is what I have found thus far:

You have omissions in the code. I am not sure if deliberate or otherwise. Specifically pizza.rb model file has the following lines missing:

has_many :pizza_toppings has_many :toppings, :through => :pizza_toppings

Also, the following line has the topping_ids missing in the same file (pizza.rb model file):

attr_accessible :name, :crispy, :crust_type_id, :topping_ids <– this is missing.

No big deal. You do talk about it in the screencast though.

Also, I really appreciate your focusing on the fundamentals. Things like how to read the API docs and find the information is very useful.

Now the question: you talk about using the collection_singular_ids=ids method which reads “Replace the collection with the objects identified by the primary keys in ids” I am trying to understand it and cannot. Are you referring to the “:topping_ids” that I point to above? The form code specific to this as I see it is below:

Toppings

<% for topping in Topping.all %> <p> <%= check_box_tag ‘pizza[topping_ids][]’, topping.id, @pizza.toppings.include?(topping) %> <%=h topping.name %> </p> <% end %> <%= hidden_field_tag ‘pizza[topping_ids][]’, ‘’ %>

I am mentally unable to make the connection between the code shown and the collection_singular_ids=ids method. A few sentences of explanation would be great.

Thanks.

Bharat

11 Jan 2009, 07:26
Generic-user-small

Erik Petersen (7 posts)

This is some confusion in the API docs. Assuming Pizza has_many :toppings then Pizza.toppings_ids is an array of all unique associated ids. I have no idea why the docs say there is a toppings_singular_ids method for the association, there isn’t. It’s just *_ids not *_signular_ids.

11 Jan 2009, 19:43
Generic-user-small

Bharat Ruparel (146 posts)

Hello Erik, I have tried to understand the API docs and here is the text that defines collection_singular_ids for has_many association:

collection_singular_ids=ids Replace the collection with the objects identified by the primary keys in ids

The way that I am reading is that collection is toppings, its singular is “topping”, therefore collection_singular_ids refers to topping_ids in this example’s context. The trouble that I am having is trying to interpret the statement “Replace the collection with the objects identified by the primary keys in ids”. I don’t see this as replacement rather, this is assignment, isn’t it? Bharat p.s. I wonder where Ryan is? Anyone seen him :)

12 Jan 2009, 02:53
Generic-user-small

Erik Petersen (7 posts)

Sorry, I misunderstood your question.

It is both from what I understand, delete_all followed by assignment.

12 Jan 2009, 23:56
Ryan_bates_cropped_pragsmall

Ryan Bates (60 posts)

Sorry for the confusion and not responding sooner about this problem. When the API documentation says “collection_singular_ids” it is referring to “topping_ids”. That is an attribute which takes an array of ids setting which toppings the pizza is associated with. It works like this:

@pizza.topping_ids = [1, 6, 8]

That will set which toppings are on the pizza.

13 Jan 2009, 14:08
Generic-user-small

Bharat Ruparel (146 posts)

Thank you.

15 Jan 2009, 11:39
Generic-user-small

Florian Witteler (4 posts)

Hi Ryan!

Great to see, that you make in-depth-screencasts here. Really helpful and I think at a fair price. I have a little feature-request: It would be great, if you offer the source-code of the starting-point (there, where you started coding in Episode #1). Speaking for myself, I learn through repetition. And since git is so easy to use, I track the code with it, and look through all changes of the commits ;-)

Kind regards from Germany, Florian

15 Jan 2009, 16:07
Ryan_bates_cropped_pragsmall

Ryan Bates (60 posts)

Hi Florian,

Thanks for your suggestion! We have thought about putting the source code on GitHub in the past, and doing so would make it possible to see each change/step I make over time during the episode. I’ll look into this more for the future episodes.

Ryan

  You must be logged in to comment