diff --git a/app/assets/javascripts/application.js b/app/assets/javascripts/application.js
index 97ab022..c641b92 100755
--- a/app/assets/javascripts/application.js
+++ b/app/assets/javascripts/application.js
@@ -21,3 +21,19 @@
//= require bootstrap/load-image.min
//= require bootstrap/image-gallery.min
//= require jquery-fileupload
+
+function insertAttachment(url,name) {
+ var ext = url.split('.').pop();
+ var img_ext = [ "jpg", "png", "bmp" , "jpeg" ];
+ var text_ext = [ "pdf" ];
+
+ if ( img_ext.indexOf(ext) > -1) {
+ tinymce.activeEditor.setContent(tinymce.activeEditor.getContent({format : 'raw'}) + "");
+ }
+ else if (text_ext.indexOf(ext) > -1) {
+ tinymce.activeEditor.setContent(tinymce.activeEditor.getContent({format : 'raw'}) + "" + name +"");
+ }
+ else {
+ alert("" + "Link");
+ }
+}
diff --git a/app/controllers/attachments_controller.rb b/app/controllers/attachments_controller.rb
index aa8ec7c..7647755 100644
--- a/app/controllers/attachments_controller.rb
+++ b/app/controllers/attachments_controller.rb
@@ -25,7 +25,9 @@ class AttachmentsController < ApplicationController
# GET /attachments/new.json
def new
@attachment = Attachment.new
-
+ @thema = Thema.find(params[:thema_id])
+ @attachment.thema = @thema
+
respond_to do |format|
format.html # new.html.erb
format.json { render json: @attachment }
@@ -35,17 +37,20 @@ class AttachmentsController < ApplicationController
# GET /attachments/1/edit
def edit
@attachment = Attachment.find(params[:id])
+ @thema = @attachment.thema
end
# POST /attachments
# POST /attachments.json
def create
@attachment = Attachment.new(params[:attachment])
-
+ @thema = Thema.find(params[:thema_id])
+ @attachment.thema_id = @thema.id
+
respond_to do |format|
if @attachment.save
- format.html { redirect_to @attachment, notice: 'Attachment was successfully created.' }
- format.json { render json: @attachment, status: :created, location: @attachment }
+ format.html { redirect_to @thema, notice: 'Attachment was successfully created.' }
+ format.json { render json: @thema, status: :created, location: @thema }
else
format.html { render action: "new" }
format.json { render json: @attachment.errors, status: :unprocessable_entity }
@@ -57,10 +62,11 @@ class AttachmentsController < ApplicationController
# PUT /attachments/1.json
def update
@attachment = Attachment.find(params[:id])
-
+ @thema = @attachment.thema
+
respond_to do |format|
if @attachment.update_attributes(params[:attachment])
- format.html { redirect_to @attachment, notice: 'Attachment was successfully updated.' }
+ format.html { redirect_to @thema, notice: 'Attachment was successfully updated.' }
format.json { head :no_content }
else
format.html { render action: "edit" }
@@ -74,9 +80,10 @@ class AttachmentsController < ApplicationController
def destroy
@attachment = Attachment.find(params[:id])
@attachment.destroy
+ @thema = Thema.find(params[:thema_id])
respond_to do |format|
- format.html { redirect_to attachments_url }
+ format.html { redirect_to @thema }
format.json { head :no_content }
end
end
diff --git a/app/models/attachment.rb b/app/models/attachment.rb
index f375f87..06f2929 100644
--- a/app/models/attachment.rb
+++ b/app/models/attachment.rb
@@ -4,6 +4,7 @@
#
# id :integer not null, primary key
# name :string(255)
+# datei :string(255)
# created_at :datetime not null
# updated_at :datetime not null
# thema_id :integer
@@ -11,9 +12,9 @@
class Attachment < ActiveRecord::Base
has_paper_trail
- attr_accessible :name
+ attr_accessible :name, :datei
belongs_to :thema
-
+ mount_uploader :datei, BeispieldateiUploader
validates :thema, :presence => true
validates :name, :presence => true
end
diff --git a/app/models/themengruppe.rb b/app/models/themengruppe.rb
index ef59efd..371ff69 100644
--- a/app/models/themengruppe.rb
+++ b/app/models/themengruppe.rb
@@ -7,7 +7,6 @@
# text :text
# created_at :datetime not null
# updated_at :datetime not null
-#
class Themengruppe < ActiveRecord::Base
WORD_COUNT = 50
diff --git a/app/views/attachments/_form.html.erb b/app/views/attachments/_form.html.erb
index 75bc493..e27d683 100644
--- a/app/views/attachments/_form.html.erb
+++ b/app/views/attachments/_form.html.erb
@@ -1,6 +1,7 @@
-<%= semantic_form_for @attachment do |f| %>
+<%= semantic_form_for [@thema,@attachment] do |f| %>
<%= f.inputs do %>
<%= f.input :name %>
+ <%= f.input :datei, :as => :file %>
<% end %>
<%= f.actions do %>
diff --git a/app/views/attachments/edit.html.erb b/app/views/attachments/edit.html.erb
index b2a2cfe..919ea5c 100644
--- a/app/views/attachments/edit.html.erb
+++ b/app/views/attachments/edit.html.erb
@@ -2,5 +2,5 @@
<%= render 'form' %>
-<%= link_to 'Show', @attachment %> |
-<%= link_to 'Back', attachments_path %>
+
+<%= link_to 'Back', thema_attachments_path(@attachment.thema,@attachment) %>
diff --git a/app/views/attachments/new.html.erb b/app/views/attachments/new.html.erb
index b7a66aa..5049aaf 100644
--- a/app/views/attachments/new.html.erb
+++ b/app/views/attachments/new.html.erb
@@ -2,4 +2,4 @@
<%= render 'form' %>
-<%= link_to 'Back', attachments_path %>
+<%= link_to 'Back', @thema %>
diff --git a/app/views/themen/_form.html.erb b/app/views/themen/_form.html.erb
index 53e9944..954b0d5 100644
--- a/app/views/themen/_form.html.erb
+++ b/app/views/themen/_form.html.erb
@@ -8,7 +8,31 @@
<% end %>
<%= tinymce %>
+
+