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