GrailsInAction / graina2

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

MEAP v13, ch6, Clarification with the redirect (Pg. 142 and 148) #65

Open tikeswar opened 10 years ago

tikeswar commented 10 years ago

A novice question ...

The redirect in Listing 6.4 addPost method passes just the id (id: params.id, Pg. 142), vs the redirect in Listing 6.5 index method passes the params itself (params: params, Pg. 148). And both the methods are redirecting to the same timeline method, so why is the difference, passing id: params.id vs. params: params? Are they equivalent? Some explanation will help for beginners like myself, thank you!

pledbrook commented 10 years ago

The question is whether you want to pass the URL parameters and POST data from the original request on to the redirect URL. You typically don't want to do this after a POST because the submitted form data would then appear in the URL parameters of the target URL. That's why only the id parameter is used for the redirect in the addPost action.

When you are dealing with a GET request and want to redirect, you often want to pass through all the URL parameters, hence why the index action uses the params argument for redirect(). It really depends on the redirect.

tikeswar commented 10 years ago

I see, thank you, Peter!

tikeswar commented 10 years ago

Oops, noticed that you have labeled it as "enhancement" for "ch06" ... so reopened it. Please feel free to close it.