Skip to content
This repository has been archived by the owner on Jul 24, 2018. It is now read-only.

Commit

Permalink
Add added on column
Browse files Browse the repository at this point in the history
  • Loading branch information
gdiggs committed Aug 25, 2012
1 parent ef2eefb commit a99a53a
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
9 changes: 6 additions & 3 deletions cataloguais.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@
configure do
config_file 'settings.yml'

# require the model(s) before setting up the database
require_relative "models/item"
DataMapper.finalize

settings.fields << 'Created At'

# set the input width based on the number of fields
set :item_width, 840 / settings.fields.count

Expand All @@ -23,9 +29,6 @@
# initialize the graph urls on startup
set :graph_urls, {}

# require the model(s) before setting up the database
require_relative "models/item"
DataMapper.finalize
end

configure :production do
Expand Down
4 changes: 4 additions & 0 deletions models/item.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ def self.search_and_sort(sort, direction = :asc, search = '')
Item.find_by_sql("SELECT * FROM items ORDER BY #{sort_options} #{direction}").select { |item| item.to_s.downcase.include? search.to_s.downcase }
end

def created_at
self.attribute_get(:created_at).strftime("%m.%d.%Y")
end

def to_a
Item.fields.collect{ |f| self.send(f) }
end
Expand Down
2 changes: 1 addition & 1 deletion views/index.haml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
- settings.fields.each do |field|
%th
- next_direction = (@sort[0] == field.robotize) ? opposite_direction : :asc
%a{ :href => "/?sort=#{field.robotize}&direction=#{next_direction}&search=#{params[:search]}" }= field
%a{ :href => "/?sort=#{field.robotize}&direction=#{next_direction}&search=#{params[:search]}" }= field.gsub(/Created At/, 'Added On')
- if @sort[0] == field.robotize
%span= (@direction == :asc) ? "\u2191" : "\u2193"
- @items.each do |item|
Expand Down

0 comments on commit a99a53a

Please sign in to comment.