From 29a35f76d8531761f2ac491642afecee249478f1 Mon Sep 17 00:00:00 2001 From: Andreas Stephanides Date: Wed, 11 Feb 2015 20:53:25 +0100 Subject: [PATCH] modify attachments --- app/controllers/attachments_controller.rb | 11 ++++++- app/models/attachment.rb | 4 +-- app/models/thema.rb | 1 + app/views/themen/_attachment_list.html.erb | 3 ++ app/views/themen/_small.html.erb | 3 +- app/views/themen/show.html.erb | 29 +++++++++++-------- config/routes.rb | 6 +++- ...20150211180445_add_parent_to_attachment.rb | 7 +++++ .../20150211180912_add_flags_to_attachment.rb | 5 ++++ 9 files changed, 52 insertions(+), 17 deletions(-) create mode 100644 db/migrate/20150211180445_add_parent_to_attachment.rb create mode 100644 db/migrate/20150211180912_add_flags_to_attachment.rb diff --git a/app/controllers/attachments_controller.rb b/app/controllers/attachments_controller.rb index 59ea3df..d05b234 100644 --- a/app/controllers/attachments_controller.rb +++ b/app/controllers/attachments_controller.rb @@ -13,6 +13,15 @@ class AttachmentsController < ApplicationController # GET /attachments/1 # GET /attachments/1.json + def set_titlepic + @attachment = Attachment.find(params[:id]) + if @attachment.image? + @attachment.flag_titlepic = params[:titlepic] + @attachment.thema.titlepics << @attachment + @attachment.save + end + redirect_to @attachment.thema + end def show @attachment = Attachment.find(params[:id]) @@ -27,7 +36,7 @@ class AttachmentsController < ApplicationController def new @attachment = Attachment.new @thema = Thema.find(params[:thema_id]) - @attachment.thema = @thema + @attachment.thema = @thema respond_to do |format| format.html # new.html.erb diff --git a/app/models/attachment.rb b/app/models/attachment.rb index 3301381..b1e7883 100644 --- a/app/models/attachment.rb +++ b/app/models/attachment.rb @@ -12,12 +12,12 @@ class Attachment < ActiveRecord::Base has_paper_trail - attr_accessible :name, :datei, :datei_cache + attr_accessible :name, :datei, :datei_cache,:flag_titlepic belongs_to :thema mount_uploader :datei, AttachmentUploader validates :thema, :presence => true validates :name, :presence => true - + belongs_to :parent, :polymorphic=>true def image? # data_ext = datei.file.extension.downcase diff --git a/app/models/thema.rb b/app/models/thema.rb index 8f5fe2a..f9d506f 100644 --- a/app/models/thema.rb +++ b/app/models/thema.rb @@ -22,6 +22,7 @@ include Rails.application.routes.url_helpers validates :themengruppe, :presence => true validates :title, :presence => true validates :text, :presence => true + has_many :titlepics, :as=>:parent, :class_name=>'Attachment', :conditions=>{:flag_titlepic=>true} has_many :meetings, :as=>:parent has_many :documents, :as=>:parent scope :public, where(:isdraft=>false).includes(:themengruppe).where("themengruppen.public"=>true) diff --git a/app/views/themen/_attachment_list.html.erb b/app/views/themen/_attachment_list.html.erb index 818aa05..d8ddb52 100644 --- a/app/views/themen/_attachment_list.html.erb +++ b/app/views/themen/_attachment_list.html.erb @@ -12,6 +12,9 @@ Actions