From 57097d16d2a7e86f9e03625fd2fb6796504c32a2 Mon Sep 17 00:00:00 2001 From: Stefan Wintermeyer Date: Sun, 13 Jan 2013 22:26:28 +0100 Subject: Bugfixes for gateway stuff. --- app/controllers/gateway_parameters_controller.rb | 23 ++++++++++++---------- app/models/gateway_parameter.rb | 8 ++++++-- app/models/gateway_setting.rb | 6 +++++- app/views/gateway_parameters/_form.html.haml | 2 +- app/views/gateway_parameters/_form_core.html.haml | 3 +-- app/views/gateway_parameters/_index_core.html.haml | 4 ++-- app/views/gateway_parameters/index.html.haml | 2 +- app/views/gateway_parameters/show.html.haml | 4 ++-- app/views/gateway_settings/_form_core.html.haml | 2 +- app/views/gateway_settings/_index_core.html.haml | 2 +- app/views/gateway_settings/show.html.haml | 2 +- app/views/gateways/_form_core.html.haml | 2 +- 12 files changed, 35 insertions(+), 25 deletions(-) (limited to 'app') diff --git a/app/controllers/gateway_parameters_controller.rb b/app/controllers/gateway_parameters_controller.rb index a5066d0..565b575 100644 --- a/app/controllers/gateway_parameters_controller.rb +++ b/app/controllers/gateway_parameters_controller.rb @@ -1,41 +1,44 @@ class GatewayParametersController < ApplicationController + load_and_authorize_resource :gateway + load_and_authorize_resource :gateway_parameter, :through => [:gateway] + def index - @gateway_parameters = GatewayParameter.all + @gateway_parameters = @gateway.gateway_parameters end def show - @gateway_parameter = GatewayParameter.find(params[:id]) + @gateway_parameter = @gateway.gateway_parameters.find(params[:id]) end def new - @gateway_parameter = GatewayParameter.new + @gateway_parameter = @gateway.gateway_parameters.build end def create - @gateway_parameter = GatewayParameter.new(params[:gateway_parameter]) + @gateway_parameter = @gateway.gateway_parameters.build(params[:gateway_parameter]) if @gateway_parameter.save - redirect_to @gateway_parameter, :notice => t('gateway_parameters.controller.successfuly_created') + redirect_to [@gateway, @gateway_parameter], :notice => t('gateway_parameters.controller.successfuly_created') else render :new end end def edit - @gateway_parameter = GatewayParameter.find(params[:id]) + @gateway_parameter = @gateway.gateway_parameters.find(params[:id]) end def update - @gateway_parameter = GatewayParameter.find(params[:id]) + @gateway_parameter = @gateway.gateway_parameters.find(params[:id]) if @gateway_parameter.update_attributes(params[:gateway_parameter]) - redirect_to @gateway_parameter, :notice => t('gateway_parameters.controller.successfuly_updated') + redirect_to [@gateway, @gateway_parameter], :notice => t('gateway_parameters.controller.successfuly_updated') else render :edit end end def destroy - @gateway_parameter = GatewayParameter.find(params[:id]) + @gateway_parameter = @gateway.gateway_parameters.find(params[:id]) @gateway_parameter.destroy - redirect_to gateway_parameters_url, :notice => t('gateway_parameters.controller.successfuly_destroyed') + redirect_to gateway_gateway_parameters_path(@gateway), :notice => t('gateway_parameters.controller.successfuly_destroyed') end end diff --git a/app/models/gateway_parameter.rb b/app/models/gateway_parameter.rb index 1875863..3dd2a95 100644 --- a/app/models/gateway_parameter.rb +++ b/app/models/gateway_parameter.rb @@ -1,13 +1,17 @@ class GatewayParameter < ActiveRecord::Base attr_accessible :gateway_id, :name, :value, :class_type, :description - belongs_to :gateway + belongs_to :gateway, :touch => true validates :name, :presence => true, - :uniqueness => true + :uniqueness => {:scope => :gateway_id} validates :class_type, :presence => true, :inclusion => { :in => ['String', 'Integer', 'Boolean'] } + + def to_s + name + end end diff --git a/app/models/gateway_setting.rb b/app/models/gateway_setting.rb index bc676a4..078901f 100644 --- a/app/models/gateway_setting.rb +++ b/app/models/gateway_setting.rb @@ -5,9 +5,13 @@ class GatewaySetting < ActiveRecord::Base validates :name, :presence => true, - :uniqueness => true + :uniqueness => {:scope => :gateway_id} validates :class_type, :presence => true, :inclusion => { :in => ['String', 'Integer', 'Boolean'] } + + def to_s + name + end end diff --git a/app/views/gateway_parameters/_form.html.haml b/app/views/gateway_parameters/_form.html.haml index 490f2a6..79342d2 100644 --- a/app/views/gateway_parameters/_form.html.haml +++ b/app/views/gateway_parameters/_form.html.haml @@ -1,4 +1,4 @@ -= simple_form_for(@gateway_parameter) do |f| += simple_form_for([@gateway, @gateway_parameter]) do |f| = f.error_notification = render "form_core", :f => f diff --git a/app/views/gateway_parameters/_form_core.html.haml b/app/views/gateway_parameters/_form_core.html.haml index 026e833..ee30238 100644 --- a/app/views/gateway_parameters/_form_core.html.haml +++ b/app/views/gateway_parameters/_form_core.html.haml @@ -1,6 +1,5 @@ .inputs - = f.input :gateway_id, :label => t('gateway_parameters.form.gateway_id.label'), :hint => conditional_hint('gateway_parameters.form.gateway_id.hint') - = f.input :name, :label => t('gateway_parameters.form.name.label'), :hint => conditional_hint('gateway_parameters.form.name.hint') + = f.input :name, :label => t('gateway_parameters.form.name.label'), :hint => conditional_hint('gateway_parameters.form.name.hint'), :autofocus => true = f.input :value, :label => t('gateway_parameters.form.value.label'), :hint => conditional_hint('gateway_parameters.form.value.hint') = f.input :class_type, :label => t('gateway_parameters.form.class_type.label'), :hint => conditional_hint('gateway_parameters.form.class_type.hint') = f.input :description, :label => t('gateway_parameters.form.description.label'), :hint => conditional_hint('gateway_parameters.form.description.hint') diff --git a/app/views/gateway_parameters/_index_core.html.haml b/app/views/gateway_parameters/_index_core.html.haml index 6209f43..3d4b6df 100644 --- a/app/views/gateway_parameters/_index_core.html.haml +++ b/app/views/gateway_parameters/_index_core.html.haml @@ -9,9 +9,9 @@ - reset_cycle - for gateway_parameter in gateway_parameters %tr{:class => cycle('odd', 'even')} - %td= gateway_parameter.gateway_id + %td= gateway_parameter.gateway %td= gateway_parameter.name %td= gateway_parameter.value %td= gateway_parameter.class_type %td= gateway_parameter.description - =render :partial => 'shared/index_view_edit_destroy_part', :locals => {:child => gateway_parameter} \ No newline at end of file + =render :partial => 'shared/index_view_edit_destroy_part', :locals => {:parent => gateway_parameter.gateway, :child => gateway_parameter} \ No newline at end of file diff --git a/app/views/gateway_parameters/index.html.haml b/app/views/gateway_parameters/index.html.haml index 1234cff..14b94b0 100644 --- a/app/views/gateway_parameters/index.html.haml +++ b/app/views/gateway_parameters/index.html.haml @@ -3,4 +3,4 @@ - if @gateway_parameters && @gateway_parameters.count > 0 = render "index_core", :gateway_parameters => @gateway_parameters -= render :partial => 'shared/create_link', :locals => {:child_class => GatewayParameter} \ No newline at end of file += render :partial => 'shared/create_link', :locals => {:parent => @gateway, :child_class => GatewayParameter} \ No newline at end of file diff --git a/app/views/gateway_parameters/show.html.haml b/app/views/gateway_parameters/show.html.haml index 87ba10d..982ffac 100644 --- a/app/views/gateway_parameters/show.html.haml +++ b/app/views/gateway_parameters/show.html.haml @@ -2,7 +2,7 @@ %p %strong= t('gateway_parameters.show.gateway_id') + ":" - = @gateway_parameter.gateway_id + = @gateway_parameter.gateway %p %strong= t('gateway_parameters.show.name') + ":" = @gateway_parameter.name @@ -16,4 +16,4 @@ %strong= t('gateway_parameters.show.description') + ":" = @gateway_parameter.description -= render :partial => 'shared/show_edit_destroy_part', :locals => { :child => @gateway_parameter } \ No newline at end of file += render :partial => 'shared/show_edit_destroy_part', :locals => { :parent => @gateway, :child => @gateway_parameter } \ No newline at end of file diff --git a/app/views/gateway_settings/_form_core.html.haml b/app/views/gateway_settings/_form_core.html.haml index 3880113..90f4eba 100644 --- a/app/views/gateway_settings/_form_core.html.haml +++ b/app/views/gateway_settings/_form_core.html.haml @@ -1,5 +1,5 @@ .inputs - = f.input :name, :label => t('gateway_settings.form.name.label'), :hint => conditional_hint('gateway_settings.form.name.hint') + = f.input :name, :label => t('gateway_settings.form.name.label'), :hint => conditional_hint('gateway_settings.form.name.hint'), :autofocus => true = f.input :value, :label => t('gateway_settings.form.value.label'), :hint => conditional_hint('gateway_settings.form.value.hint') = f.input :class_type, :label => t('gateway_settings.form.class_type.label'), :hint => conditional_hint('gateway_settings.form.class_type.hint') = f.input :description, :label => t('gateway_settings.form.description.label'), :hint => conditional_hint('gateway_settings.form.description.hint') diff --git a/app/views/gateway_settings/_index_core.html.haml b/app/views/gateway_settings/_index_core.html.haml index 5b93f16..ca4ce09 100644 --- a/app/views/gateway_settings/_index_core.html.haml +++ b/app/views/gateway_settings/_index_core.html.haml @@ -14,4 +14,4 @@ %td= gateway_setting.value %td= gateway_setting.class_type %td= gateway_setting.description - =render :partial => 'shared/index_view_edit_destroy_part', :locals => {:parent => gateway_setting.gateway, :child_class => gateway_setting} \ No newline at end of file + =render :partial => 'shared/index_view_edit_destroy_part', :locals => {:parent => gateway_setting.gateway, :child => gateway_setting} \ No newline at end of file diff --git a/app/views/gateway_settings/show.html.haml b/app/views/gateway_settings/show.html.haml index 14de6de..7a9ecc3 100644 --- a/app/views/gateway_settings/show.html.haml +++ b/app/views/gateway_settings/show.html.haml @@ -16,4 +16,4 @@ %strong= t('gateway_settings.show.description') + ":" = @gateway_setting.description -= render :partial => 'shared/show_edit_destroy_part', :locals => {:parent => @gateway_setting.gateway, :child_class => @gateway_setting} \ No newline at end of file += render :partial => 'shared/show_edit_destroy_part', :locals => {:parent => @gateway_setting.gateway, :child => @gateway_setting} \ No newline at end of file diff --git a/app/views/gateways/_form_core.html.haml b/app/views/gateways/_form_core.html.haml index 3545772..13ed8b1 100644 --- a/app/views/gateways/_form_core.html.haml +++ b/app/views/gateways/_form_core.html.haml @@ -1,5 +1,5 @@ .inputs - = f.input :name, :label => t('gateways.form.name.label'), :hint => conditional_hint('gateways.form.name.hint') + = f.input :name, :label => t('gateways.form.name.label'), :hint => conditional_hint('gateways.form.name.hint'), :autofocus => true = f.input :technology, :label => t('gateways.form.technology.label'), :hint => conditional_hint('gateways.form.technology.hint') = f.input :inbound, :label => t('gateways.form.inbound.label'), :hint => conditional_hint('gateways.form.inbound.hint') = f.input :outbound, :label => t('gateways.form.outbound.label'), :hint => conditional_hint('gateways.form.outbound.hint') -- cgit v1.2.3