Sunday, March 21, 2010 by Brandon
Comments
I rarely use the rdocs or ri docs that build with gems when you install them, as it’s usually easier for me to just search it online. I get tired of trying to remember the command line option to not generate the docs, so I created an alias I thought I’d share with everyone.
For example, in Mac OS X, include this code in your ~/.bash_login file:
alias grind='gem install --no-rdoc --no-ri'
Then, when you want to install a gem (i.e. rails), instead of calling ‘gem install rails —no-rdoc—no-ri’, use:
grind rails
Monday, October 05, 2009 by Brandon
Comments
I couldn’t find a local DataStore Data Viewer anywhere. After a lot of searching I found that it’s actually pretty simple.
- Start up your application
- Point your browser to: http://localhost:8080/_ah/admin/
I haven’t tried this with the Python version of App Engine, but I know it works on Java.
Updated: It does work with the Python version of App Engine.
Read the whole discussion where I found the solution to this issue.
Friday, July 31, 2009 by Brandon
Comments
I ran into an annoying problem while developing a Grails application. I could create a message in flash scope and display it in view in a normal controller, but that same flash message would not appear if I was inside a webflow. The variable would just be null. I finally found the reason for this after reading a ton of Grails documentation. Apparently, a webflow in Grails actually merges all the flash, flow, and conversation scoped variables into the Model view before rendering it. So you shouldn’t reference variables in the view by scope, instead you should reference them just by name.
For example, instead of writing this in your GSP view:
<g:if test="${flash.message}">
<div class="message">${flash.message}</div>
</g:if>
You would just write this:
<g:if test="${message}">
<div class="message">${message}</div>
</g:if>
Thursday, July 02, 2009 by Brandon
Comments
When you define a has-many relationship on a domain model in Grails, it automatically creates the collection for you and the getters/setters to make it a property. By default, doing something like this:
class Author implements Serializable {
String name
static def hasMany = [books: Book]
}
creates a java.util.Set called books in your model that you can access using author.books. A problem arises when you don’t want that collection to be a plain old set (P.O.S.) What if you want it to be a SortedSet or possibly a list so you can access elements like author.books[1]? It’s easy to force GORM to create that collection as something other than a Set: just create a property with the same name of the type of collection class you want. So our previous example becomes:
class Author implements Serializable {
String name
List books
static def hasMany = [books: Book]
}
Now author.books is a List instead of a Set. It’s as simple as that.