diff options
author | Stefan Wintermeyer <stefan.wintermeyer@amooma.de> | 2013-01-05 12:42:53 +0100 |
---|---|---|
committer | Stefan Wintermeyer <stefan.wintermeyer@amooma.de> | 2013-01-05 12:42:53 +0100 |
commit | 01f2ab4e3d5694de81f6ebb594e0e852616ebbd9 (patch) | |
tree | 48613822df4082b080e1ecb68a6c38c1fbdadbfb /app | |
parent | 380a4cdfe5cfa573fb916ca7c2145a6062ef8198 (diff) |
Added GsParameter model as a replacement for gemeinschaft_parameters.rb
Diffstat (limited to 'app')
-rw-r--r-- | app/controllers/gs_parameters_controller.rb | 83 | ||||
-rw-r--r-- | app/helpers/gs_parameters_helper.rb | 2 | ||||
-rw-r--r-- | app/models/gs_parameter.rb | 28 | ||||
-rw-r--r-- | app/views/gs_parameters/_form.html.erb | 14 | ||||
-rw-r--r-- | app/views/gs_parameters/edit.html.erb | 6 | ||||
-rw-r--r-- | app/views/gs_parameters/index.html.erb | 29 | ||||
-rw-r--r-- | app/views/gs_parameters/new.html.erb | 5 | ||||
-rw-r--r-- | app/views/gs_parameters/show.html.erb | 25 |
8 files changed, 192 insertions, 0 deletions
diff --git a/app/controllers/gs_parameters_controller.rb b/app/controllers/gs_parameters_controller.rb new file mode 100644 index 0000000..d6a92c6 --- /dev/null +++ b/app/controllers/gs_parameters_controller.rb @@ -0,0 +1,83 @@ +class GsParametersController < ApplicationController + # GET /gs_parameters + # GET /gs_parameters.json + def index + @gs_parameters = GsParameter.all + + respond_to do |format| + format.html # index.html.erb + format.json { render json: @gs_parameters } + end + end + + # GET /gs_parameters/1 + # GET /gs_parameters/1.json + def show + @gs_parameter = GsParameter.find(params[:id]) + + respond_to do |format| + format.html # show.html.erb + format.json { render json: @gs_parameter } + end + end + + # GET /gs_parameters/new + # GET /gs_parameters/new.json + def new + @gs_parameter = GsParameter.new + + respond_to do |format| + format.html # new.html.erb + format.json { render json: @gs_parameter } + end + end + + # GET /gs_parameters/1/edit + def edit + @gs_parameter = GsParameter.find(params[:id]) + end + + # POST /gs_parameters + # POST /gs_parameters.json + def create + @gs_parameter = GsParameter.new(params[:gs_parameter]) + + respond_to do |format| + if @gs_parameter.save + format.html { redirect_to @gs_parameter, notice: 'Gs parameter was successfully created.' } + format.json { render json: @gs_parameter, status: :created, location: @gs_parameter } + else + format.html { render action: "new" } + format.json { render json: @gs_parameter.errors, status: :unprocessable_entity } + end + end + end + + # PUT /gs_parameters/1 + # PUT /gs_parameters/1.json + def update + @gs_parameter = GsParameter.find(params[:id]) + + respond_to do |format| + if @gs_parameter.update_attributes(params[:gs_parameter]) + format.html { redirect_to @gs_parameter, notice: 'Gs parameter was successfully updated.' } + format.json { head :no_content } + else + format.html { render action: "edit" } + format.json { render json: @gs_parameter.errors, status: :unprocessable_entity } + end + end + end + + # DELETE /gs_parameters/1 + # DELETE /gs_parameters/1.json + def destroy + @gs_parameter = GsParameter.find(params[:id]) + @gs_parameter.destroy + + respond_to do |format| + format.html { redirect_to gs_parameters_url } + format.json { head :no_content } + end + end +end diff --git a/app/helpers/gs_parameters_helper.rb b/app/helpers/gs_parameters_helper.rb new file mode 100644 index 0000000..ec339ea --- /dev/null +++ b/app/helpers/gs_parameters_helper.rb @@ -0,0 +1,2 @@ +module GsParametersHelper +end diff --git a/app/models/gs_parameter.rb b/app/models/gs_parameter.rb new file mode 100644 index 0000000..d0cc37a --- /dev/null +++ b/app/models/gs_parameter.rb @@ -0,0 +1,28 @@ +class GsParameter < ActiveRecord::Base + validates :name, + :presence => true, + :uniqueness => true + + validates :value, + :presence => true + + validates :class_type, + :presence => true, + :inclusion => { :in => ['String', 'Integer', 'Boolean', 'YAML'] } + + def generate_contant + Kernel.const_set(self.name, self.value.to_i) if self.class_type == 'Integer' + Kernel.const_set(self.name, self.value.to_s) if self.class_type == 'String' + + if self.class_type == 'Boolean' + Kernel.const_set(self.name, true) if self.value == 'true' + Kernel.const_set(self.name, false) if self.value == 'false' + end + + Kernel.const_set(self.name, YAML.load(self.value)) if self.class_type == 'YAML' + end + + def to_s + name + end +end diff --git a/app/views/gs_parameters/_form.html.erb b/app/views/gs_parameters/_form.html.erb new file mode 100644 index 0000000..13ad26f --- /dev/null +++ b/app/views/gs_parameters/_form.html.erb @@ -0,0 +1,14 @@ +<%= simple_form_for(@gs_parameter) do |f| %> + <%= f.error_notification %> + + <div class="inputs"> + <%= f.input :name %> + <%= f.input :section %> + <%= f.input :value %> + <%= f.input :class_type %> + </div> + + <div class="actions"> + <%= f.button :submit %> + </div> +<% end %> diff --git a/app/views/gs_parameters/edit.html.erb b/app/views/gs_parameters/edit.html.erb new file mode 100644 index 0000000..6938a40 --- /dev/null +++ b/app/views/gs_parameters/edit.html.erb @@ -0,0 +1,6 @@ +<h1>Editing gs_parameter</h1> + +<%= render 'form' %> + +<%= link_to 'Show', @gs_parameter %> | +<%= link_to 'Back', gs_parameters_path %> diff --git a/app/views/gs_parameters/index.html.erb b/app/views/gs_parameters/index.html.erb new file mode 100644 index 0000000..dee6838 --- /dev/null +++ b/app/views/gs_parameters/index.html.erb @@ -0,0 +1,29 @@ +<h1>Listing gs_parameters</h1> + +<table> + <tr> + <th>Name</th> + <th>Section</th> + <th>Value</th> + <th>Class type</th> + <th></th> + <th></th> + <th></th> + </tr> + +<% @gs_parameters.each do |gs_parameter| %> + <tr> + <td><%= gs_parameter.name %></td> + <td><%= gs_parameter.section %></td> + <td><%= gs_parameter.value %></td> + <td><%= gs_parameter.class_type %></td> + <td><%= link_to 'Show', gs_parameter %></td> + <td><%= link_to 'Edit', edit_gs_parameter_path(gs_parameter) %></td> + <td><%= link_to 'Destroy', gs_parameter, confirm: 'Are you sure?', method: :delete %></td> + </tr> +<% end %> +</table> + +<br /> + +<%= link_to 'New Gs parameter', new_gs_parameter_path %> diff --git a/app/views/gs_parameters/new.html.erb b/app/views/gs_parameters/new.html.erb new file mode 100644 index 0000000..a357e2e --- /dev/null +++ b/app/views/gs_parameters/new.html.erb @@ -0,0 +1,5 @@ +<h1>New gs_parameter</h1> + +<%= render 'form' %> + +<%= link_to 'Back', gs_parameters_path %> diff --git a/app/views/gs_parameters/show.html.erb b/app/views/gs_parameters/show.html.erb new file mode 100644 index 0000000..1f03542 --- /dev/null +++ b/app/views/gs_parameters/show.html.erb @@ -0,0 +1,25 @@ +<p id="notice"><%= notice %></p> + +<p> + <b>Name:</b> + <%= @gs_parameter.name %> +</p> + +<p> + <b>Section:</b> + <%= @gs_parameter.section %> +</p> + +<p> + <b>Value:</b> + <%= @gs_parameter.value %> +</p> + +<p> + <b>Class type:</b> + <%= @gs_parameter.class_type %> +</p> + + +<%= link_to 'Edit', edit_gs_parameter_path(@gs_parameter) %> | +<%= link_to 'Back', gs_parameters_path %> |