Developer's Blog

Using the Search Language to search across associations

Posted July 08, 2009 by Justin Lewis. Filed under Code.

Interface has a unique Search Language that allows you to easily search for content, from simple queries on one field to multiple grouped conditional statements. Also, because content can have associated items, there is the ability to search across those associations. Here’s how.

Using Search in Content Tag

Assuming your model is called Product, place the following in your template:

<% content_tag(:model => :product).each do |product| -%>
<h3><%= product.name %></h3>
<% end -%>

That will get all content from the Product model. But what if you wanted to show only Products that had a certain ProductCategory?

<% content_tag(:model => :blog_item, :find => "product_category.name!Widgets").each do |product| -%>
<h3><%= product.name %></h3>
<% end -%>

Even more, you can search across any time of association. If the Product has multiple ProductCategories, you could also do:

<% content_tag(:model => :blog_item, :find => "(product_categories.name!Widgets|product_categories.name!Thingies)").each do |product| -%>
<h3><%= product.name %></h3>
<% end -%>

Which would pull all Products that are in either the Widgets or Thingies ProductCategories.

Using the API

You can use the same Search Language in the API to pull content:

http://yoursite.interfacecms.com/api/product.xml?search=(product_categories.name!Widgets|product_categories.name!Thingies)

For more on info, see the Search Language Documentation and the Content Tag Documentation in the Interface User Manual.

Add comment

Blueprint CSS Framework

Posted July 02, 2009 by Justin Lewis. Filed under Tips.

Blueprint is a CSS framework, which aims to cut down on your development time. It gives you a solid foundation to build your project on top of, with an easy-to-use grid, sensible typography, useful plugins, and even a stylesheet for printing.

Read more at blueprintcss.org

Add comment

Using Rescue Statement When Outputting Data in ERB

Posted May 26, 2009 by Justin Lewis. Filed under Code.

Sometimes when you’re writing ERB, you’ll have to output something like this:

<%= article.category.name %>

But if the category is not set, you’ll probably get an error page with a nasty backtrace of an exception, along with an error like:

undefined method 'name' for nilclass

There are a couple ways to avoid this. First, you can test if category is nil before outputting the value:

<% if not article.category.blank? -%>
<%= article.category.name %>
<% else -%>
No Category
<% end -%>

Another way that is a bit cleaner is to add a rescue statement to the end of your output:

<%= article.category.name rescue 'No Category' %>

Using rescue will only catch exceptions, and will not test if the name itself is nil or an empty string. So, use either one based on your situation.

Add comment

Gaia Flash Framework

Posted May 06, 2009 by Justin Lewis. Filed under Tips.

Gaia is an open-source front-end Flash Framework for AS3 and AS2 designed to dramatically reduce development time.

Read more at gaiaflashframework.com

Add comment