diff options
| author | Luc Donnet | 2014-08-22 12:48:35 +0200 |
|---|---|---|
| committer | Luc Donnet | 2014-08-22 12:48:35 +0200 |
| commit | 71ce5bca071ad06e22feaab08e32c70336e11958 (patch) | |
| tree | a667badd46b3129f4601635f33329ab9e4020a27 /app/controllers | |
| parent | 330501d4ad75d97d9c649880f1a932b3e5fa2077 (diff) | |
| parent | b827bc2007a820341314da284a83a431803a573f (diff) | |
| download | chouette-core-71ce5bca071ad06e22feaab08e32c70336e11958.tar.bz2 | |
Merge branch 'sismo' of github.com:afimb/chouette2 into sismo
Diffstat (limited to 'app/controllers')
| -rw-r--r-- | app/controllers/time_table_combinations_controller.rb | 23 | ||||
| -rw-r--r-- | app/controllers/vehicle_translations_controller.rb | 35 |
2 files changed, 46 insertions, 12 deletions
diff --git a/app/controllers/time_table_combinations_controller.rb b/app/controllers/time_table_combinations_controller.rb index baaf90fec..32a3dcab9 100644 --- a/app/controllers/time_table_combinations_controller.rb +++ b/app/controllers/time_table_combinations_controller.rb @@ -1,24 +1,39 @@ class TimeTableCombinationsController < ChouetteController - respond_to :js, :only => [:create] + respond_to :js, :only => [:new,:create] belongs_to :referential do belongs_to :time_table, :parent_class => Chouette::TimeTable end + after_filter :clean_flash + + def clean_flash + # only run this in case it's an Ajax request. + return unless request.xhr? + flash.discard + end + + def new + @time_table_combination = TimeTableCombination.new(:source_id => parent.id) + render :action => :new + end + def create @time_table_combination = TimeTableCombination.new( params[:time_table_combination].merge( :source_id => parent.id)) - #@time_table = parent @year = params[:year] ? params[:year].to_i : Date.today.cwyear if @time_table_combination.valid? begin @time_table = @time_table_combination.combine flash[:notice] = t('time_table_combinations.success') render "create_success" - rescue Exception=> e - Rails.logger.error "Error: #{e}" + rescue => e + Rails.logger.error( "TimeTableCombination error, @time_table_combination=#{@time_table_combination.inspect}") + Rails.logger.error( e.inspect) flash[:error] = t('time_table_combinations.failure') render "create_failure" end + else + render "create_failure" end end diff --git a/app/controllers/vehicle_translations_controller.rb b/app/controllers/vehicle_translations_controller.rb index af54001ae..65a0db7fe 100644 --- a/app/controllers/vehicle_translations_controller.rb +++ b/app/controllers/vehicle_translations_controller.rb @@ -1,5 +1,5 @@ class VehicleTranslationsController < ChouetteController - respond_to :html, :only => [:create] + respond_to :js, :only => [:new, :create] belongs_to :referential do belongs_to :line, :parent_class => Chouette::Line do @@ -8,17 +8,36 @@ class VehicleTranslationsController < ChouetteController end end end + after_filter :clean_flash + + def clean_flash + # only run this in case it's an Ajax request. + return unless request.xhr? + + flash.discard + end + + def new + @vehicle_translation = VehicleTranslation.new( :vehicle_journey_id => parent.id, :count => 1, :duration => 1) + render :action => :new + end def create + @vehicle_translation = VehicleTranslation.new( params[:vehicle_translation].merge( :vehicle_journey_id => parent.id)) + begin - translation = VehicleTranslation.new( params[:vehicle_translation].merge( :vehicle_journey_id => parent.id)) - translation.translate - flash[:notice] = t('vehicle_translations.success', :count => translation.count) - rescue + if @vehicle_translation.valid? + @vehicle_translation.translate + flash[:notice] = t('vehicle_translations.success', :count => @vehicle_translation.count) + else + flash[:alert] = @vehicle_translation.errors[ :vehicle_journey_id] unless @vehicle_translation.errors[ :vehicle_journey_id].empty? + end + rescue => e + Rails.logger.error( "VehicleTranslation error, @vehicle_translation=#{@vehicle_translation.inspect}") + Rails.logger.error( e.inspect) flash[:alert] = t('vehicle_translations.failure') end - redirect_to referential_line_route_vehicle_journeys_path(@referential, @line, @route) - + render :action => :new end - + end |
