简体   繁体   中英

Grails Blurb Plugin - Unable to resolve class Blurb

I'm working through the book Grails: A Quick-Start Guide and have come upon a problem. The book has me install the Blurb plugin, which seems to work, but states that we will be using it as if it were a domain class and using it a pre-existing controller. The code that I am to add to the controller looks like this

def blurb = Blurb.findByName("custom_${event.id}" )
if (!blurb){
    blurb = new Blurb(name:"custom_${event.id}" , content:"" ).save()
}

When I do this I receive the same error in the IDE and the run output

' unable to resolve class Blurb ' and I am directed specifically to this line blurb = new Blurb(name:"custom_${event.id}" , content:"" ).save()

Can anyone tell me what might be going wrong? I'm assuming the plugin is installed properly because if I try to access it's controller/action directly ' http://localhost:8080/TekDays/blurb/create ' the plugin's provided view renders properly.

Thanks!

-- For reference I am using STS / Grails 1.3.7


Update 2011.05.12 7:45AM CST

I've attached a screenshot showing my project from the STS interface to show how my project is laid out in the event that it is package related as Burt indicated. The issue though is I'm not sure how do to the import statement so perhaps that screenshot will help.

Here is the current code in the Dashboard Controller.

package tekdays

class DashboardController {
...
}

I've tried adding the following lines per Burt's suggestion, but I obviously don't have it right

package tekdays
package my.package  <--unexpected token: package

class DashboardController {

I tried changing out my with tekdays and default and both yield the same result.

Am I doing that wrong?

Thanks!

Grails ScreenShot

The Blurb class is in the default package, so if your controller is in a package you'll need to use a Groovy trick to access it:

package my.package

import Blurb as Blurb

class MyController {

   def action = {
      def blurb = Blurb.findByName("custom_${event.id}" )
      if (!blurb) {
         blurb = new Blurb(name:"custom_${event.id}" , content:"" ).save()
      }
   }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM