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

@@ -35,6 +35,7 @@ GEM
sass (~> 3.2)
builder (3.0.4)
cancan (1.6.9)
cocaine (0.4.2)
coffee-rails (3.2.2)
coffee-script (>= 2.2.0)
railties (~> 3.2.0)
@@ -77,6 +78,12 @@ GEM
paper_trail (2.7.0)
activerecord (~> 3.0)
railties (~> 3.0)
paperclip (3.4.0)
activemodel (>= 3.0.0)
activerecord (>= 3.0.0)
activesupport (>= 3.0.0)
cocaine (~> 0.4.0)
mime-types
polyglot (0.3.3)
rack (1.4.5)
rack-cache (1.2)
@@ -142,17 +149,18 @@ DEPENDENCIES
bootstrap-sass (~> 2.2.0)
cancan
coffee-rails (~> 3.2.1)
devise
execjs
formtastic
devise (~> 2.2.3)
execjs (~> 1.4.0)
formtastic (~> 2.2.1)
formtastic-bootstrap
globalize3
globalize3 (~> 0.3.0)
jquery-rails
paper_trail
paper_trail (>= 2.7.0)
paperclip (~> 3.4.0)
rails (= 3.2.9)
rolify
sass-rails (~> 3.2.3)
sqlite3
therubyracer
tinymce-rails
tinymce-rails (>= 3.5.8)
uglifier (>= 1.0.3)

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%>

View File

@@ -23,4 +23,6 @@ inflect.singular 'modulgruppen', 'modulgruppe'
inflect.irregular 'modulgruppe', 'modulgruppen'
inflect.plural 'rubrik', 'rubriken'
inflect.singular 'rubriken', 'rubrik'
inflect.plural 'beispiel', 'beispiele'
inflect.singular 'beispiele', 'beispiel'
end

View File

@@ -2,6 +2,9 @@ Fetsite::Application.routes.draw do
resources :beispiele
devise_for :users
scope '(:locale)/admin' do
resources :users

View File

@@ -0,0 +1,21 @@
class CreateBeispiele < ActiveRecord::Migration
def up
create_table :beispiele do |t|
t.string :name
t.text :desc
t.integer :lva_id
t.timestamps
end
add_attachment :beispiele, :file
Beispiel.create_translation_table!({
:desc => :text,
})
add_column :beispiel_translations, :beispiele_id, :integer
remove_column :beispiel_translations, :beispiel_id
end
def down
Beispiel.drop_translation_table! #:migrate_data => true
drop_table :beispiele
end
end

View File

@@ -11,7 +11,29 @@
#
# It's strongly recommended to check this file into your version control system.
ActiveRecord::Schema.define(:version => 20130124223508) do
ActiveRecord::Schema.define(:version => 20130214233723) do
create_table "beispiel_translations", :force => true do |t|
t.string "locale"
t.text "desc"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
t.integer "beispiele_id"
end
add_index "beispiel_translations", ["locale"], :name => "index_beispiel_translations_on_locale"
create_table "beispiele", :force => true do |t|
t.string "name"
t.text "desc"
t.integer "lva_id"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
t.string "file_file_name"
t.string "file_content_type"
t.integer "file_file_size"
t.datetime "file_updated_at"
end
create_table "lva_translations", :force => true do |t|
t.integer "lva_id"
@@ -33,7 +55,6 @@ ActiveRecord::Schema.define(:version => 20130124223508) do
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
t.integer "modul_id"
t.integer "semester_id"
end
create_table "lvas_moduls", :id => false, :force => true do |t|
@@ -84,9 +105,10 @@ ActiveRecord::Schema.define(:version => 20130124223508) do
create_table "moduls", :force => true do |t|
t.string "name"
t.text "desc"
t.text "depend"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
t.text "depend"
t.integer "studium_id"
end
create_table "neuigkeiten", :force => true do |t|
@@ -120,8 +142,8 @@ ActiveRecord::Schema.define(:version => 20130124223508) do
create_table "semesters", :force => true do |t|
t.string "name"
t.integer "nummer"
t.integer "studium_id"
t.string "ssws"
t.boolean "ws"
t.boolean "ss"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
end
@@ -129,7 +151,6 @@ ActiveRecord::Schema.define(:version => 20130124223508) do
create_table "studien", :force => true do |t|
t.string "zahl"
t.string "name"
t.text "shortdesc"
t.text "desc"
t.string "typ"
t.datetime "created_at", :null => false
@@ -139,7 +160,6 @@ ActiveRecord::Schema.define(:version => 20130124223508) do
create_table "studium_translations", :force => true do |t|
t.string "locale"
t.text "desc"
t.text "shortdesc"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
t.integer "studien_id"

9
test/fixtures/beispiele.yml vendored Normal file
View File

@@ -0,0 +1,9 @@
# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/Fixtures.html
one:
name:
desc: MyText
two:
name:
desc: MyText

View File

@@ -0,0 +1,49 @@
require 'test_helper'
class BeispieleControllerTest < ActionController::TestCase
setup do
@beispiel = beispiele(:one)
end
test "should get index" do
get :index
assert_response :success
assert_not_nil assigns(:beispiele)
end
test "should get new" do
get :new
assert_response :success
end
test "should create beispiel" do
assert_difference('Beispiel.count') do
post :create, beispiel: { desc: @beispiel.desc, name: @beispiel.name }
end
assert_redirected_to beispiel_path(assigns(:beispiel))
end
test "should show beispiel" do
get :show, id: @beispiel
assert_response :success
end
test "should get edit" do
get :edit, id: @beispiel
assert_response :success
end
test "should update beispiel" do
put :update, id: @beispiel, beispiel: { desc: @beispiel.desc, name: @beispiel.name }
assert_redirected_to beispiel_path(assigns(:beispiel))
end
test "should destroy beispiel" do
assert_difference('Beispiel.count', -1) do
delete :destroy, id: @beispiel
end
assert_redirected_to beispiele_path
end
end

View File

@@ -0,0 +1,7 @@
require 'test_helper'
class BeispielTest < ActiveSupport::TestCase
# test "the truth" do
# assert true
# end
end

View File

@@ -0,0 +1,4 @@
require 'test_helper'
class BeispieleHelperTest < ActionView::TestCase
end