Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Open Source > BOOK: Professional Ruby On Rails ISBN: 978-0-470-22388-8
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
BOOK: Professional Ruby On Rails ISBN: 978-0-470-22388-8
This is the forum to discuss the Wrox book Professional Ruby on Rails by Noel Rappin; ISBN: 9780470223888
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Professional Ruby On Rails ISBN: 978-0-470-22388-8 section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old April 6th, 2009, 04:40 AM
Registered User
 
Join Date: Apr 2009
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default Ingredients list doubles in size when recipe is edited

Hi Noel, I see that you have not replied to any threads since November so I'm guess that I might be wasting my time here.....

Anyway, I have a problem with the book.

When I try to edit a recipe using the 'edit' button, the list of ingredients doubles in size.

It's looks like the 'create' method of the ingredients controller is being called whenever the update edit/update method(s) of the recipe controller are called.

Anyone else having this problem? What is the best way of dealing with this?
Reply With Quote
  #2 (permalink)  
Old April 8th, 2009, 11:38 AM
Registered User
 
Join Date: Apr 2009
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default

post edited

Last edited by stephen murdoch; April 8th, 2009 at 11:52 AM.
Reply With Quote
  #3 (permalink)  
Old April 8th, 2009, 11:48 AM
Wrox Author
 
Join Date: Mar 2008
Location: , , .
Posts: 41
Thanks: 0
Thanked 2 Times in 2 Posts
Send a message via AIM to noelrap
Default Ingredients list doubles in size when recipe is edited Reply to Thread

Stephen,

Let's lower the temperature here a bit.

a) It's been two days since you've posted here and I've been on vacation for half of that time. Also, this isn't my day job, so my time for digging through this is limited.

b) I will take a look at this issue and try to get back to you later this week.

Noel
Reply With Quote
  #4 (permalink)  
Old April 8th, 2009, 11:58 AM
Registered User
 
Join Date: Apr 2009
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default

thanks, just keeping you all on your toes.

i know it was a bit cheeky.

I was under the impression that the board was not being read as there are questions posted in november which have not had any replies.

appologies
Reply With Quote
  #5 (permalink)  
Old May 8th, 2009, 08:39 PM
Registered User
 
Join Date: Apr 2009
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default

is there any word on this? the problem still occurs.
Reply With Quote
  #6 (permalink)  
Old May 8th, 2009, 08:52 PM
Registered User
 
Join Date: Apr 2009
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default

is there any word on this? the problem still occurs.

Here's what's happening:

I create a recipe with '1 can beans' as an ingredient,
Then I decide that I need to edit the description of the recipe so I click the 'edit recipe' button
When I hit submit, there are now 2 entries for '1 can beans'.
If I edit the description (or anything else) again, there will be 4 entries for '1 can beans'

If however, after clicking 'edit recipe' I remove the entries for '1 can beans' from the edit form, then the number of entries for '1 can beans' remains as it was, it does not increase in size and it does not decrease in size.

This happens using the code I wrote whilst following along and it also happens if I just run the exact code from the downloaded zip file provided here at wrox.com

I'm confused.
Reply With Quote
  #7 (permalink)  
Old May 27th, 2009, 11:07 PM
Wrox Author
 
Join Date: Mar 2008
Location: , , .
Posts: 41
Thanks: 0
Thanked 2 Times in 2 Posts
Send a message via AIM to noelrap
Default

The amazing thing about this is that I somehow didn't catch it before the book came out.

Anyway, what's happening here is a common mistake in parent/child relationships...

When you submit the recipe form, the text of the ingredients is in the
Code:
ingredient_string
field, which is then set using the method
Code:
recipe#ingredient_string
, which parses the strings and then adds them to the to the ingredient list [code]self.ingredients << ingredient[code]. The problem is that the original ingredients are still there, so the new ones are added on top of the originals, in effect duplicating the ingredients.

The workaround would be to start the
Code:
recipe#ingredient_string
method with something like
Code:
recipe.ingredients.clear
, but you'd want to put that in some kind of transaction block so that the ingredients aren't deleted incorrectly.

Sorry for the wait, hope this helps.
Reply With Quote
  #8 (permalink)  
Old May 29th, 2009, 09:53 AM
Registered User
 
Join Date: Apr 2009
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi

thanks a lot for the resolution

I've not tried it yet as I'm in work but I will give it a shot when I get home,

Incidentally, I developed a workaround by just removing the ingredients from the from but it will be nice fix it.

thanks
Steve
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Recipe to change CR query at run time. dbron Crystal Reports 4 June 24th, 2009 04:07 AM
cannot show edited rows after a save greenbriar BOOK: Beginning Visual Basic 2005 Databases ISBN: 978-0-7645-8894-5 2 January 13th, 2009 04:22 PM
Size of text box depending on size of another box AstridVM BOOK: Access 2003 VBA Programmer's Reference 0 March 7th, 2007 06:24 AM
How to lock particular cell for being edited sunil menghani Excel VBA 7 October 18th, 2006 12:07 AM
VC++ 6.0, Edit Boxes, and doubles Spivonious Visual C++ 1 August 9th, 2004 12:38 PM



All times are GMT -4. The time now is 04:31 PM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.