GrailsInAction / graina2

Source code for the 2nd edition of Grails in Action
90 stars 92 forks source link

MEAP v13, ch6, Issues with Listing 6.4 (PostController.groovy, Pg. 142) #63

Closed tikeswar closed 10 years ago

tikeswar commented 10 years ago

Have couple of issues with Listing 6.4 (PostController.groovy, Pg. 142):

1. In the code it reads def addPost = {. Should it be def addPost() { on a newline instead?

2. Issue with the params. If I do as in the listing def post = new Post(params), I get an error. However, if I do def post = new Post(content: params.content) it seems to work fine. Can someone please explain the difference?

I am using Grails version: 2.3.1

Thank you in advance for your help.

pledbrook commented 10 years ago
  1. Yes, it should be a method. The code should still work as it is though.
  2. What's the error you're getting? The first form binds all the parameters in params to the new Post instance whereas the second will only populate the content property.
tikeswar commented 10 years ago

Hi Peter:

1. I see, thank you!

2. It is working fine now, and not getting that error. Thank you for the explanation!