Commit a7ea976f authored by surma Lodur's avatar surma Lodur
Browse files

added image uploader

parent fca19b80
...@@ -51,6 +51,8 @@ group :doc do ...@@ -51,6 +51,8 @@ group :doc do
end end
group :development do group :development do
gem 'capistrano'
gem 'better_errors'
gem 'database_cleaner' gem 'database_cleaner'
gem 'rails-erd' gem 'rails-erd'
gem 'ffaker' gem 'ffaker'
......
...@@ -59,6 +59,9 @@ GEM ...@@ -59,6 +59,9 @@ GEM
arel (4.0.2) arel (4.0.2)
atomic (1.1.14) atomic (1.1.14)
bcrypt-ruby (3.1.2) bcrypt-ruby (3.1.2)
better_errors (1.1.0)
coderay (>= 1.0.0)
erubis (>= 2.6.6)
bootstrap-sass (3.1.0.2) bootstrap-sass (3.1.0.2)
sass (~> 3.2) sass (~> 3.2)
bourbon (3.1.8) bourbon (3.1.8)
...@@ -66,6 +69,10 @@ GEM ...@@ -66,6 +69,10 @@ GEM
thor thor
builder (3.1.4) builder (3.1.4)
cancan (1.6.10) cancan (1.6.10)
capistrano (3.1.0)
i18n
rake (>= 10.0.0)
sshkit (~> 1.3)
celluloid (0.15.2) celluloid (0.15.2)
timers (~> 1.1.0) timers (~> 1.1.0)
celluloid-io (0.15.0) celluloid-io (0.15.0)
...@@ -144,6 +151,9 @@ GEM ...@@ -144,6 +151,9 @@ GEM
mime-types (1.25.1) mime-types (1.25.1)
minitest (4.7.5) minitest (4.7.5)
multi_json (1.8.4) multi_json (1.8.4)
net-scp (1.1.2)
net-ssh (>= 2.6.5)
net-ssh (2.8.0)
nio4r (1.0.0) nio4r (1.0.0)
orm_adapter (0.5.0) orm_adapter (0.5.0)
paperclip (4.1.1) paperclip (4.1.1)
...@@ -231,6 +241,12 @@ GEM ...@@ -231,6 +241,12 @@ GEM
activesupport (>= 3.0) activesupport (>= 3.0)
sprockets (~> 2.8) sprockets (~> 2.8)
sqlite3 (1.3.8) sqlite3 (1.3.8)
sshkit (1.3.0)
net-scp (>= 1.1.2)
net-ssh
term-ansicolor
term-ansicolor (1.3.0)
tins (~> 1.0)
therubyracer (0.12.1) therubyracer (0.12.1)
libv8 (~> 3.16.14.0) libv8 (~> 3.16.14.0)
ref ref
...@@ -239,6 +255,7 @@ GEM ...@@ -239,6 +255,7 @@ GEM
atomic atomic
tilt (1.4.1) tilt (1.4.1)
timers (1.1.0) timers (1.1.0)
tins (1.0.0)
treetop (1.4.15) treetop (1.4.15)
polyglot polyglot
polyglot (>= 0.3.1) polyglot (>= 0.3.1)
...@@ -261,8 +278,10 @@ PLATFORMS ...@@ -261,8 +278,10 @@ PLATFORMS
DEPENDENCIES DEPENDENCIES
activeadmin! activeadmin!
better_errors
bootstrap-sass bootstrap-sass
cancan cancan
capistrano
coffee-rails (~> 4.0.0) coffee-rails (~> 4.0.0)
database_cleaner database_cleaner
devise devise
......
ActiveAdmin.register Quest do ActiveAdmin.register Quest do
form :html => { :enctype => "multipart/form-data" } do |f|
f.inputs "Details" do
f.input :title
f.input :points
f.input :description
f.input :image, :as => :file, :hint => f.template.image_tag(f.object.image.url(:thumb)), :required => false
end
f.actions
end
# See permitted parameters documentation: # See permitted parameters documentation:
# https://github.com/gregbell/active_admin/blob/master/docs/2-resource-customization.md#setting-up-strong-parameters # https://github.com/gregbell/active_admin/blob/master/docs/2-resource-customization.md#setting-up-strong-parameters
# #
...@@ -13,5 +21,5 @@ ActiveAdmin.register Quest do ...@@ -13,5 +21,5 @@ ActiveAdmin.register Quest do
# permitted << :other if resource.something? # permitted << :other if resource.something?
# permitted # permitted
# end # end
end end
ActiveAdmin.register Reward do ActiveAdmin.register Reward do
form :html => { :enctype => "multipart/form-data" } do |f|
f.inputs "Details" do
f.input :title
f.input :points
f.input :description
f.input :image, :as => :file, :hint => f.template.image_tag(f.object.image.url(:thumb)), :required => false
end
f.actions
end
# See permitted parameters documentation: # See permitted parameters documentation:
# https://github.com/gregbell/active_admin/blob/master/docs/2-resource-customization.md#setting-up-strong-parameters # https://github.com/gregbell/active_admin/blob/master/docs/2-resource-customization.md#setting-up-strong-parameters
......
...@@ -8,6 +8,15 @@ class Quest < ActiveRecord::Base ...@@ -8,6 +8,15 @@ class Quest < ActiveRecord::Base
validates :points, :numericality => {:greater_than => 0} validates :points, :numericality => {:greater_than => 0}
has_attached_file(:image, {
:styles => {:thumb => "22x22>" },
:default_url => "/images/:style/missing.png"
})
validates_attachment_content_type :image, :content_type => ["image/jpg", "image/jpeg", "image/png"]
# attr_accessible :title, :points, :description, :image
def solve(hacker, user = nil) def solve(hacker, user = nil)
hacker.earnings.create({ hacker.earnings.create({
:user => user, :user => user,
......
...@@ -8,6 +8,10 @@ class Reward < ActiveRecord::Base ...@@ -8,6 +8,10 @@ class Reward < ActiveRecord::Base
validates :points, :numericality => {:greater_than => 0} validates :points, :numericality => {:greater_than => 0}
has_attached_file :image, :styles => {:thumb => "22x22>" }, :default_url => "/images/:style/missing.png"
validates_attachment_content_type :image, :content_type => ["image/jpg", "image/jpeg", "image/png"]
def earn(hacker, user = nil) def earn(hacker, user = nil)
hacker.redemptions.create({ hacker.redemptions.create({
:user => user, :user => user,
......
...@@ -6,7 +6,9 @@ ...@@ -6,7 +6,9 @@
<div class="row"> <div class="row">
<div class="col-xs-2"> <div class="col-xs-2">
<!-- TODO: should be replaced with paperclip gem --> <!-- TODO: should be replaced with paperclip gem -->
<span class="glyphicon <%= quest.image_url %>"> </span> <span class="glyphicon">
<%=image_tag quest.image.url(:thumb) %>
</span>
</div> </div>
<div class="col-xs-7"> <div class="col-xs-7">
<%= quest.title %> <%= quest.title %>
......
...@@ -6,7 +6,9 @@ ...@@ -6,7 +6,9 @@
<div class="row"> <div class="row">
<div class="col-xs-2"> <div class="col-xs-2">
<!-- TODO: should be replaced with paperclip gem --> <!-- TODO: should be replaced with paperclip gem -->
<span class="glyphicon <%= reward.image_url %>"> </span> <span class="glyphicon">
<%=image_tag reward.image.url(:thumb) %>
</span>
</div> </div>
<div class="col-xs-7"> <div class="col-xs-7">
<%= reward.title %> <%= reward.title %>
......
ActiveAdmin.setup do |config| ActiveAdmin.setup do |config|
config.before_filter do
params.permit!
end
# == Site Title # == Site Title
# #
# Set the title that is displayed on the main layout # Set the title that is displayed on the main layout
......
class AddAttachementsToQuestsAndRewards < ActiveRecord::Migration
def change
add_attachment :quests, :image
add_attachment :rewards, :image
end
end
class RemoveImageUrlFromQuestAndReward < ActiveRecord::Migration
def change
change_table(:quests) do |t|
t.remove :image_url
end
change_table(:rewards) do |t|
t.remove :image_url
end
end
end
...@@ -11,7 +11,7 @@ ...@@ -11,7 +11,7 @@
# #
# It's strongly recommended that you check this file into your version control system. # It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 20140312192849) do ActiveRecord::Schema.define(version: 20140312201127) do
create_table "active_admin_comments", force: true do |t| create_table "active_admin_comments", force: true do |t|
t.string "namespace" t.string "namespace"
...@@ -89,9 +89,12 @@ ActiveRecord::Schema.define(version: 20140312192849) do ...@@ -89,9 +89,12 @@ ActiveRecord::Schema.define(version: 20140312192849) do
t.integer "points" t.integer "points"
t.string "title" t.string "title"
t.string "description" t.string "description"
t.string "image_url"
t.datetime "created_at" t.datetime "created_at"
t.datetime "updated_at" t.datetime "updated_at"
t.string "image_file_name"
t.string "image_content_type"
t.integer "image_file_size"
t.datetime "image_updated_at"
end end
create_table "redemptions", force: true do |t| create_table "redemptions", force: true do |t|
...@@ -107,10 +110,13 @@ ActiveRecord::Schema.define(version: 20140312192849) do ...@@ -107,10 +110,13 @@ ActiveRecord::Schema.define(version: 20140312192849) do
create_table "rewards", force: true do |t| create_table "rewards", force: true do |t|
t.integer "points" t.integer "points"
t.string "title" t.string "title"
t.string "image_url"
t.string "description" t.string "description"
t.datetime "created_at" t.datetime "created_at"
t.datetime "updated_at" t.datetime "updated_at"
t.string "image_file_name"
t.string "image_content_type"
t.integer "image_file_size"
t.datetime "image_updated_at"
end end
end end
...@@ -12,34 +12,29 @@ Reward.delete_all ...@@ -12,34 +12,29 @@ Reward.delete_all
Quest.create({ Quest.create({
:title => 'Küche aufgeräumt', :title => 'Küche aufgeräumt',
:points => 50, :points => 50
:image_url => 'glyphicon-fire'
}) })
Quest.create({ Quest.create({
:title => 'Müll rausgebracht', :title => 'Müll rausgebracht',
:points => 1, :points => 1
:image_url => 'glyphicon-trash'
}) })
Quest.create({ Quest.create({
:title => 'Getränke gekauft', :title => 'Getränke gekauft',
:points => 5, :points => 5
:image_url => 'glyphicon-glass'
}) })
Reward.create({ Reward.create({
:title => 'Roter Artikel (Getränk)', :title => 'Roter Artikel (Getränk)',
:points => 15, :points => 15
:image_url => 'icon-beer'
}) })
Reward.create({ Reward.create({
:title => 'Gelber Artikel (Snack)', :title => 'Gelber Artikel (Snack)',
:points => 10, :points => 10
:image_url => 'icon-drink'
}) })
Reward.create({ Reward.create({
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment