modify attachments
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -12,6 +12,9 @@
|
||||
<a class="dropdown-toggle" data-toggle="dropdown" href="#">Actions</a>
|
||||
<ul class="dropdown-menu">
|
||||
<li>
|
||||
<%= link_to ff_icon("icon-pencil")+"Make Titlepic", set_titlepic_thema_attachment_path(a.thema,a,:params=>{:titlepic=>true}) %>
|
||||
</li>
|
||||
<li>
|
||||
<%= link_to ff_icon("icon-pencil")+"Edit", edit_thema_attachment_path(a.thema,a) %>
|
||||
</li><li>
|
||||
<%= link_to "Delete Attachment", thema_attachment_path(a.thema,a), method: "DELETE", confirm: "Sure?" , class: "btn-danger " %>
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
<% if can? :show, small %>
|
||||
<a name="thema_<%=small.id%>" href="#<%=small.id%>">
|
||||
<h2><%= small.title %> <%= link_to fa_icon("pencil"), verwalten_thema_path(small) if can? :edit, small %> </h2>
|
||||
<h2><%= link_to small.title,small %> <%= link_to fa_icon("pencil"), verwalten_thema_path(small) if can? :edit, small %> </h2>
|
||||
</a>
|
||||
<%= image_tag small.titlepics.first.datei.url unless small.titlepics.first.nil? %>
|
||||
<% if small.is_outdated? %>
|
||||
<div class="sticker sticker-red"> <%= I18n.t("thema.outdated") %> <%= link_to"Als aktuell markieren",is_updated_thema_path(small), :class=>:btn if can? :is_updated, small%></div>
|
||||
<% end %>
|
||||
|
||||
@@ -1,19 +1,24 @@
|
||||
<%= content_for :header do %>
|
||||
<title><%= @thema.title.to_s + " (" + @thema.themengruppe.title.to_s + ")" %></title>
|
||||
|
||||
<% unless @thema.attachments.first.nil?
|
||||
# picture_url=URI(root_url)
|
||||
# picture_url.path=@thema.picture.url(:locale=>nil, :theme=>nil)
|
||||
end
|
||||
<%
|
||||
mog = {
|
||||
:title => @thema.title.to_s + " (" + @thema.themengruppe.title.to_s + ")",
|
||||
:type => "article",
|
||||
:description =>@thema.text_first_words,
|
||||
:url=>thema_url(:theme=>nil)
|
||||
}
|
||||
%>
|
||||
<% set_meta_tags :og => {
|
||||
:title => @thema.title.to_s + " (" + @thema.themengruppe.title.to_s + ")",
|
||||
:type => "article",
|
||||
:description =>@thema.text_first_words,
|
||||
:url=>thema_url(:theme=>nil)
|
||||
}
|
||||
|
||||
<%=
|
||||
unless @thema.titlepics.first.nil?
|
||||
picture_url=URI(root_url)
|
||||
picture_url.path=@thema.titlepics.first.datei.url(:locale=>nil, :theme=>nil)
|
||||
mog[:image]= picture_url
|
||||
end
|
||||
%>
|
||||
<%= display_meta_tags %>
|
||||
<%= mog.to_yaml %>
|
||||
<%= display_meta_tags :og=> mog %>
|
||||
<% end %>
|
||||
|
||||
<p id="notice"><%= notice %></p>
|
||||
|
||||
@@ -157,7 +157,11 @@
|
||||
get :documents
|
||||
get :meetings
|
||||
end
|
||||
resources :attachments
|
||||
resources :attachments do
|
||||
member do
|
||||
get :set_titlepic
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
resources :calendars
|
||||
|
||||
7
db/migrate/20150211180445_add_parent_to_attachment.rb
Normal file
7
db/migrate/20150211180445_add_parent_to_attachment.rb
Normal file
@@ -0,0 +1,7 @@
|
||||
class AddParentToAttachment < ActiveRecord::Migration
|
||||
def change
|
||||
change_table :attachments do |t|
|
||||
t.references :parent, :polymorphic=>{:default=>'Thema'}
|
||||
end
|
||||
end
|
||||
end
|
||||
5
db/migrate/20150211180912_add_flags_to_attachment.rb
Normal file
5
db/migrate/20150211180912_add_flags_to_attachment.rb
Normal file
@@ -0,0 +1,5 @@
|
||||
class AddFlagsToAttachment < ActiveRecord::Migration
|
||||
def change
|
||||
add_column :attachments, :flag_titlepic, :boolean
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user