Beispiele hinzugefügt

This commit is contained in:
Andreas Stephanides
2013-02-15 10:48:52 +01:00
parent 154e338360
commit 19b4ed31f4
23 changed files with 305 additions and 19 deletions

View File

@@ -0,0 +1,3 @@
# Place all the behaviors and hooks related to the matching controller here.
# All this logic will automatically be available in application.js.
# You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/

View File

@@ -0,0 +1,3 @@
// Place all the styles related to the beispiele controller here.
// They will automatically be included in application.css.
// You can use Sass (SCSS) here: http://sass-lang.com/

View File

@@ -0,0 +1,83 @@
class BeispieleController < ApplicationController
# GET /beispiele
# GET /beispiele.json
def index
@beispiele = Beispiel.all
respond_to do |format|
format.html # index.html.erb
format.json { render json: @beispiele }
end
end
# GET /beispiele/1
# GET /beispiele/1.json
def show
@beispiel = Beispiel.find(params[:id])
respond_to do |format|
format.html # show.html.erb
format.json { render json: @beispiel }
end
end
# GET /beispiele/new
# GET /beispiele/new.json
def new
@beispiel = Beispiel.new
respond_to do |format|
format.html # new.html.erb
format.json { render json: @beispiel }
end
end
# GET /beispiele/1/edit
def edit
@beispiel = Beispiel.find(params[:id])
end
# POST /beispiele
# POST /beispiele.json
def create
@beispiel = Beispiel.new(params[:beispiel])
respond_to do |format|
if @beispiel.save
format.html { redirect_to @beispiel, notice: 'Beispiel was successfully created.' }
format.json { render json: @beispiel, status: :created, location: @beispiel }
else
format.html { render action: "new" }
format.json { render json: @beispiel.errors, status: :unprocessable_entity }
end
end
end
# PUT /beispiele/1
# PUT /beispiele/1.json
def update
@beispiel = Beispiel.find(params[:id])
respond_to do |format|
if @beispiel.update_attributes(params[:beispiel])
format.html { redirect_to @beispiel, notice: 'Beispiel was successfully updated.' }
format.json { head :no_content }
else
format.html { render action: "edit" }
format.json { render json: @beispiel.errors, status: :unprocessable_entity }
end
end
end
# DELETE /beispiele/1
# DELETE /beispiele/1.json
def destroy
@beispiel = Beispiel.find(params[:id])
@beispiel.destroy
respond_to do |format|
format.html { redirect_to beispiele_url }
format.json { head :no_content }
end
end
end

View File

@@ -0,0 +1,2 @@
module BeispieleHelper
end

7
app/models/beispiel.rb Normal file
View File

@@ -0,0 +1,7 @@
class Beispiel < ActiveRecord::Base
has_paper_trail
attr_accessible :desc, :name, :file, :lva_id
has_attached_file :file
belongs_to :lva
translates :desc, :fallbacks_for_empty_translations => true
end

View File

@@ -4,4 +4,5 @@ class Lva < ActiveRecord::Base
has_and_belongs_to_many :modul
has_and_belongs_to_many :semester
translates :desc, :fallbacks_for_empty_translations => true
has_many :beispiele , :class_name => "Beispiel"
end

View File

@@ -9,7 +9,5 @@ def moderator
end
end
def moderator=(id)
User.find(id).add_role(:newsmoderator, self)
end
end

View File

@@ -0,0 +1,12 @@
<%= semantic_form_for @beispiel, :html => { :multipart => true } do |f| %>
<%= f.inputs do %>
<%= f.input :name %>
<%= f.input :desc %>
<%= f.input :file , :as=>:file %>
<%= f.input :lva, :as=>:radio, :collection => Lva.all%>
<% end %>
<%= f.actions do %>
<%= f.action :submit, :as => :input %>
<% end %>
<% end %>

View File

@@ -0,0 +1,6 @@
<h1>Editing beispiel</h1>
<%= render 'form' %>
<%= link_to 'Show', @beispiel %> |
<%= link_to 'Back', beispiele_path %>

View File

@@ -0,0 +1,25 @@
<h1>Listing beispiele</h1>
<table>
<tr>
<th>Name</th>
<th>Desc</th>
<th></th>
<th></th>
<th></th>
</tr>
<% @beispiele.each do |beispiel| %>
<tr>
<td><%= beispiel.name %></td>
<td><%= beispiel.desc %></td>
<td><%= link_to 'Show', beispiel %></td>
<td><%= link_to 'Edit', edit_beispiel_path(beispiel) %></td>
<td><%= link_to 'Destroy', beispiel, method: :delete, data: { confirm: 'Are you sure?' } %></td>
</tr>
<% end %>
</table>
<br />
<%= link_to 'New Beispiel', new_beispiel_path %>

View File

@@ -0,0 +1,5 @@
<h1>New beispiel</h1>
<%= render 'form' %>
<%= link_to 'Back', beispiele_path %>

View File

@@ -0,0 +1,16 @@
<p id="notice"><%= notice %></p>
<p>
<b>Name:</b>
<%= @beispiel.name %>
</p>
<p>
<b>Desc:</b>
<%= @beispiel.desc %>
<%= @beispiel.file.url %>
</p>
<%= link_to 'Edit', edit_beispiel_path(@beispiel) %> |
<%= link_to 'Back', beispiele_path %>

View File

@@ -16,5 +16,7 @@
<p>
<%= @lva.desc %>
</p>
<% @lva.beispiele.each do |beispiel| %>
<%= link_to beispiel.name, beispiel.file.url %>
<% end%>