diff --git a/app/controllers/budgets/investments_controller.rb b/app/controllers/budgets/investments_controller.rb
index 799d1f76d..fd5feccc2 100644
--- a/app/controllers/budgets/investments_controller.rb
+++ b/app/controllers/budgets/investments_controller.rb
@@ -106,7 +106,7 @@ module Budgets
def investment_params
params.require(:budget_investment).permit(:title, :description, :external_url, :heading_id, :tag_list,
- :organization_name, :location, :terms_of_service,
+ :organization_name, :location, :terms_of_service, :image,
documents_attributes: [:id, :title, :attachment, :cached_attachment, :user_id])
end
diff --git a/app/models/budget/investment.rb b/app/models/budget/investment.rb
index d658e7ab2..4a19dd27f 100644
--- a/app/models/budget/investment.rb
+++ b/app/models/budget/investment.rb
@@ -28,6 +28,9 @@ class Budget
has_many :comments, as: :commentable
has_many :milestones
+ has_attached_file :image, styles: { large: "600x600>" ,medium: "300x300>", thumb: "100x100>" }
+ validates_attachment_content_type :image, content_type: /\Aimage\/.*\z/
+
validates :title, presence: true
validates :author, presence: true
validates :description, presence: true
diff --git a/app/views/budgets/investments/_form.html.erb b/app/views/budgets/investments/_form.html.erb
index 8f98b9d5c..bbc7f7c84 100644
--- a/app/views/budgets/investments/_form.html.erb
+++ b/app/views/budgets/investments/_form.html.erb
@@ -1,4 +1,4 @@
-<%= form_for(@investment, url: form_url, method: :post) do |f| %>
+<%= form_for(@investment, url: form_url, method: :post, html: { multipart: true }) do |f| %>
<%= render 'shared/errors', resource: @investment %>
@@ -53,6 +53,9 @@
data: {js_url: suggest_tags_path} %>
+
+ <%= f.file_field :image %>
+
<% unless current_user.manager? %>
diff --git a/app/views/budgets/investments/_investment.html.erb b/app/views/budgets/investments/_investment.html.erb
index f65b9cfe5..efdfa6d64 100644
--- a/app/views/budgets/investments/_investment.html.erb
+++ b/app/views/budgets/investments/_investment.html.erb
@@ -43,6 +43,12 @@
<% unless investment.unfeasible? %>
+ <% if investment.image.exists? %>
+
+ <%= image_tag investment.image.url(:medium) %>
+
+ <% end %>
+
<% if investment.should_show_votes? %>
diff --git a/app/views/budgets/investments/_investment_show.html.erb b/app/views/budgets/investments/_investment_show.html.erb
index db2a2562d..6d71c32bd 100644
--- a/app/views/budgets/investments/_investment_show.html.erb
+++ b/app/views/budgets/investments/_investment_show.html.erb
@@ -37,6 +37,10 @@
<% end %>
+ <% if investment.image.exists? %>
+ <%= image_tag investment.image.url(:large) %>
+ <% end %>
+
<%= render 'shared/tags', taggable: investment %>
<%= safe_html_with_links investment.description.html_safe %>
diff --git a/db/migrate/20170606094459_add_attachment_image_to_budget_investments.rb b/db/migrate/20170606094459_add_attachment_image_to_budget_investments.rb
new file mode 100644
index 000000000..c0b6b2393
--- /dev/null
+++ b/db/migrate/20170606094459_add_attachment_image_to_budget_investments.rb
@@ -0,0 +1,11 @@
+class AddAttachmentImageToBudgetInvestments < ActiveRecord::Migration
+ def self.up
+ change_table :budget_investments do |t|
+ t.attachment :image
+ end
+ end
+
+ def self.down
+ remove_attachment :budget_investments, :image
+ end
+end
diff --git a/db/schema.rb b/db/schema.rb
index 240abcdaa..0b63e2866 100644
--- a/db/schema.rb
+++ b/db/schema.rb
@@ -161,6 +161,10 @@ ActiveRecord::Schema.define(version: 20170918231410) do
t.boolean "winner", default: false
t.boolean "incompatible", default: false
t.integer "community_id"
+ t.string "image_file_name"
+ t.string "image_content_type"
+ t.integer "image_file_size"
+ t.datetime "image_updated_at"
end
add_index "budget_investments", ["administrator_id"], name: "index_budget_investments_on_administrator_id", using: :btree