Skip to content

Instantly share code, notes, and snippets.

<div class="container">
<div class="row">
<div class="span3">
<div class="well sidebar-nav">
<ul class="nav nav-list">
<li class="nav-header">Sidebar</li>
<li class="active"><a href="#">Link</a></li>
<li><a href="#">Link</a></li>
<li><a href="#">Link</a></li>
<li><a href="#">Link</a></li>
<ul class="nav">
<li <?=active($page,1)?>><a href="/">Home</a></li>
<li <?=active($page,2)?>><a href="<?=base_url()?>welcome/about">About</a></li>
<li <?=active($page,3)?>><a href="<?=base_url()?>welcome/stories">Short Stories</a></li>
<li <?=active($page,4)?>><a href="<?=base_url()?>welcome/contact">Contact</a></li>
</ul>
class AddSlugToArticles < ActiveRecord::Migration
def change
add_column :articles, :slug, :string
add_index :articles, :slug
end
end
<h2>Recent Articles</h2>
<table class="table table-bordered">
<% @articles.each do |article| %>
<tr>
<td><%= link_to article.title, article %></td>
</tr>
<tr>
<td><em>Posted: <%= article.created_at.strftime('%a %d %B %Y - %H:%M') %></em></td>
</tr>
<% end %>
<h2>Recent Drafts</h2>
<table class="table table-bordered">
<% @articles.each do |article| %>
<tr>
<td><%= article.title %></td>
</tr>
<tr>
<td><em>Posted: <%= article.created_at.strftime('%a %d %B %Y - %H:%M') %></em></td>
</tr>
<tr>
<h1><%=@count%> Notes (<%=@cat.name%>)</h1>
<% unless @notes.nil? %>
<ul>
<% @notes.each do |note| %>
<li><a href="/note/<%= note.id %>"><%= note.title %></a> </li>
<% end %>
</ul>
<%= will_paginate @notes %>
<% else %>
get '/notes/:category' do
@notes = Note.all.paginate(:category_id => params[:category],:page => params[:page], :per_page => 10)
@cat = Category.get(params[:category])
erb :notes
end
<h2>Notes Categories</h2>
<% unless @categories.nil? %>
<ul>
<% @categories.each do |category| %>
<li><a href="/notes/<%= category.id %>"><%= category.name %></a></li>
<% end %>
</ul>
<% else %>
<p>No notes categories at the moment :-(</p>
class Category
include DataMapper::Resource
property :id, Serial
property :name, String
has n, :notes
end
class Note
get '/' do
@categories = Category.all(:order => [ :id.asc ])
erb :home
end