Skip to content

Instantly share code, notes, and snippets.

@rvanlieshout
Created November 7, 2011 12:44
Show Gist options
  • Save rvanlieshout/1344840 to your computer and use it in GitHub Desktop.
Save rvanlieshout/1344840 to your computer and use it in GitHub Desktop.
<tbody>
<% products.each do |product| %>
<tr>
<td><%= link_to product.name, product %></td>
<td><%= truncate(strip_tags(product.description), :length => 80) %></td>
<td><%= product.price %></td>
</tr>
<% end %>
</tbody>
class CategoriesController < ApplicationController
before_filter :set_categories, :only => [ :index, :show ]
def index
end
def show
@category = Category.find(params[:id])
@title = @category.name
end
def new
@category = Category.new
@title = "Add Category"
end
def create
@category = Category.new(params[:category])
if @category.save
redirect_to @category
else
@title = "Add category"
render 'new'
end
end
protected
def set_categories
@categories = Category.all
end
end
<div class="span-6">
<%= render :partial => "index" %>
</div>
<div class="span-18 last">
<% unless @category.products.empty? %>
<table>
<thead>
<tr>
<th>Product name</th>
<th>Description</th>
<th>Price</th>
</tr>
</thead>
<%= render :partial => "products", :locals => { :products => @category.products } %>
</table>
<% end %>
</div>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment