Commit a7ea976f authored by surma Lodur's avatar surma Lodur

added image uploader

parent fca19b80
......@@ -51,6 +51,8 @@ group :doc do
end
group :development do
gem 'capistrano'
gem 'better_errors'
gem 'database_cleaner'
gem 'rails-erd'
gem 'ffaker'
......
......@@ -59,6 +59,9 @@ GEM
arel (4.0.2)
atomic (1.1.14)
bcrypt-ruby (3.1.2)
better_errors (1.1.0)
coderay (>= 1.0.0)
erubis (>= 2.6.6)
bootstrap-sass (3.1.0.2)
sass (~> 3.2)
bourbon (3.1.8)
......@@ -66,6 +69,10 @@ GEM
thor
builder (3.1.4)
cancan (1.6.10)
capistrano (3.1.0)
i18n
rake (>= 10.0.0)
sshkit (~> 1.3)
celluloid (0.15.2)
timers (~> 1.1.0)
celluloid-io (0.15.0)
......@@ -144,6 +151,9 @@ GEM
mime-types (1.25.1)
minitest (4.7.5)
multi_json (1.8.4)
net-scp (1.1.2)
net-ssh (>= 2.6.5)
net-ssh (2.8.0)
nio4r (1.0.0)
orm_adapter (0.5.0)
paperclip (4.1.1)
......@@ -231,6 +241,12 @@ GEM
activesupport (>= 3.0)
sprockets (~> 2.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)
libv8 (~> 3.16.14.0)
ref
......@@ -239,6 +255,7 @@ GEM
atomic
tilt (1.4.1)
timers (1.1.0)
tins (1.0.0)
treetop (1.4.15)
polyglot
polyglot (>= 0.3.1)
......@@ -261,8 +278,10 @@ PLATFORMS
DEPENDENCIES
activeadmin!
better_errors
bootstrap-sass
cancan
capistrano
coffee-rails (~> 4.0.0)
database_cleaner
devise
......
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:
# 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
# permitted << :other if resource.something?
# permitted
# end
end
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:
# 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
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)
hacker.earnings.create({
:user => user,
......
......@@ -8,6 +8,10 @@ class Reward < ActiveRecord::Base
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)
hacker.redemptions.create({
:user => user,
......
......@@ -6,7 +6,9 @@
<div class="row">
<div class="col-xs-2">
<!-- 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 class="col-xs-7">
<%= quest.title %>
......
......@@ -6,7 +6,9 @@
<div class="row">
<div class="col-xs-2">
<!-- 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 class="col-xs-7">
<%= reward.title %>
......
ActiveAdmin.setup do |config|
config.before_filter do
params.permit!
end
# == Site Title
#
# 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 @@
#
# 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|
t.string "namespace"
......@@ -89,9 +89,12 @@ ActiveRecord::Schema.define(version: 20140312192849) do
t.integer "points"
t.string "title"
t.string "description"
t.string "image_url"
t.datetime "created_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
create_table "redemptions", force: true do |t|
......@@ -107,10 +110,13 @@ ActiveRecord::Schema.define(version: 20140312192849) do
create_table "rewards", force: true do |t|
t.integer "points"
t.string "title"
t.string "image_url"
t.string "description"
t.datetime "created_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
......@@ -12,34 +12,29 @@ Reward.delete_all
Quest.create({
:title => 'Küche aufgeräumt',
:points => 50,
:image_url => 'glyphicon-fire'
:points => 50
})
Quest.create({
:title => 'Müll rausgebracht',
:points => 1,
:image_url => 'glyphicon-trash'
:points => 1
})
Quest.create({
:title => 'Getränke gekauft',
:points => 5,
:image_url => 'glyphicon-glass'
:points => 5
})
Reward.create({
:title => 'Roter Artikel (Getränk)',
:points => 15,
:image_url => 'icon-beer'
:points => 15
})
Reward.create({
:title => 'Gelber Artikel (Snack)',
:points => 10,
:image_url => 'icon-drink'
:points => 10
})
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