Skip to content

Instantly share code, notes, and snippets.

View coderberry's full-sized avatar

Eric Berry coderberry

View GitHub Profile
# Create the plugin
./script/generate plugin flash_helper
# init.rb
require File.dirname(__FILE__) + '/lib/flash_helper'
ActionView::Base.send(:include, FlashHelper)
# flash_helper.rb
module FlashHelper
def display_flash(flash)
1.- rails jukebox -d mysql
2.- cd jukebox
3.- vi config/database.yml
4.- rake db:create:all
5.- ruby script/generate scaffold Artist name:string permalink:string albums_count:integer
6.- ruby script/generate scaffold Album artist:references title:string permalink:string
7.- Edit your db/migrate 001_create_artists migration file to initialize the counter cache for artists_count and add the index for the permalink column.
def self.up
create_table :artists do |t|
def c = Transaction.createCriteria()
def cnt = c.get {
projections {
sum("amount")
}
eq("status", k)
eq("transactionType", transactionType)
ge("dateTimeProcessed", cal1.getTime())
le("dateTimeProcessed", cal2.getTime())
}
def c = Transaction.createCriteria()
def cnt = c.get {
projections {
sum("amount")
}
and {
eq("status", k)
eq("transactionType", transactionType)
ge("dateTimeProcessed", cal1.getTime())
le("dateTimeProcessed", cal2.getTime())
class Book {
def grailsApplication
String title
Float cost
static constraints = {
title(blank: false)
cost(blank: false)
class CommonTagLib {
static namespace = 'berry'
def formatXML = { attrs, body ->
String rawXML = body().toString()
try {
def slurpedXML = new XmlSlurper().parseText(rawXML)
def writer = new StringWriter()
new XmlNodePrinter(new PrintWriter(writer)).print(slurpedXML)
def berry = grailsApplication.mainContext.getBean('CommonTagLib')
return berry.formatXML("....")
<html>
<head>
<meta name="layout" content="admintasia"/>
<meta name="pageHeader" content="This is a test" />
<meta name="pageSubHeader" content="blah blah blah" />
</head>
<body>
...
<h2><g:pageProperty name="meta.pageHeader" default="MISSING PAGE HEADER" /></h2>
<h4><g:pageProperty name="meta.pageSubHeader" default="" /></h4>
package berry
import org.springframework.web.multipart.MultipartFile
import org.codehaus.groovy.grails.web.context.ServletContextHolder
class FileUploadService {
boolean transactional = true
def String uploadFile(MultipartFile file, String name, String destinationDirectory) {