GrailsInAction / graina2

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

MEAP ch1 v12, Section 1.5.1 #54

Closed tikeswar closed 10 years ago

tikeswar commented 10 years ago

I am new to Groovy and Grails, and following the Grails In Acton 2nd Edition step-by-step to learn from scratch. Have a question on Section 1.5.1 Scaffolding: add rocket fuel

Question:

After following step-by-step, and browsing to http://localhost:8080/qotd/quote/list gives the following error (have also attached a figure)

HTTP Status 404 - /qotd/quote/list type Status report message /qotd/quote/list description The requested resource is not available. Apache Tomcat/7.0.42 qotd_quote_list

However, browsing to http://localhost:8080/qotd/quote/create works fine (matches with Figure 1.12 in the book), and I am able to create a new quote. At this url, if I hover/click on the "Quote List" button it shows/takes me to http://localhost:8080/qotd/quote/index (and NOT to the list of quotes). Please see that attached figure. qotd_quote_create

The versions I am using are: App version: 0.1 Grails version: 2.3.1 Groovy version: 2.1.8 JVM version: 1.7.0_45

Is this a bug in Grails or I am missing something?

Thank you and any help would be highly appreciated.

pledbrook commented 10 years ago

This is a breaking change with Grails 2.3. The list action no longer exists in the scaffolding. We will need to update the chapter and source code to use the index action instead.

tikeswar commented 10 years ago

Thank you, Peter. With your help above, and looking at the official "Scaffolding - Reference Documentation" at http://grails.org/doc/latest/guide/scaffolding.html (currently for the version 2.3.1), I think it works now.

I commented out the entire index method in the QuoteController.groovy class as follows, and it seems to work now (meaning, I am able to see the quote list which I was not able to see before).

//def index() { 
//redirect(action: "home")
//}

Thank you again for the quick feedback, it was very helpful (especially for a newbie like myself).

pledbrook commented 10 years ago

Glad it's working for you. I'd like to keep this open as a reminder that we need to update the QOTD app.

mairoo commented 10 years ago

I see the index page, but I cannot see the list Larry, Chuck and Eric's quotes.

I inserted three record using "grails console", and it prints 3 when I command "print qotd.Quote.count()"

Interestingly I don't see the 3 results in scaffolding index(list) page.

What's wrong with my index page?

Grails 2.3.4

pledbrook commented 10 years ago

Have you switched to a persistent database? If not, any changes you make via the console UI will not have an effect on the running application.

mairoo commented 10 years ago

Thank you for your response.

I changed my environment settings for development as follwos:

development {
    dataSource {
        dbCreate = "update" // one of 'create', 'create-drop', 'update', 'validate', ''
        url = "jdbc:h2:file:~/devDb;MVCC=TRUE;LOCK_TIMEOUT=10000;DB_CLOSE_ON_EXIT=FALSE"
    }
}

I believe that it's enough to use persistent database.

I see the results "grails console". I can retreive results using random() action method described in your book.

I cannot see the three records only when I access the index() page supported by "scaffolding".

It's quite weired.

I tried to import your qotd application provided in github. It doesn't seem to work with Grails 2.3.4.

Can I know which version I have to choose on the fly?

mairoo commented 10 years ago

Hmm...

I found an answer here: http://www.grailsexample.net/instant-ui-dynamic-scaffolding/#comment-29334

However, it sees like a bug of Grails 2.3.4 because I have to pass the List even using "dynamic" scaffolding like:

def index() {
    [quoteInstanceList : Quote.list()]
}

I believe that some contents must be changed if your book's supposed to support the latest version of Grails.

Thank you.

pledbrook commented 10 years ago

The sample source code is now based on Grails 2.3.4. @nasiajai please check your code against that. You should not be overriding the index action in your controller.