diff options
| author | Marc Florisson | 2014-08-21 16:37:30 +0200 |
|---|---|---|
| committer | Marc Florisson | 2014-08-21 16:37:30 +0200 |
| commit | 0bc1d3150175f7db4942003af9a5ba641cce3ffd (patch) | |
| tree | d247d90349a5782248e5f23e2152375e1b33dedd /app/controllers | |
| parent | 008432840b80e4fa3a1bc4e0410d604e74d0e0e4 (diff) | |
| download | chouette-core-0bc1d3150175f7db4942003af9a5ba641cce3ffd.tar.bz2 | |
refactor and extends vehicle translation. Mantis 26839
Diffstat (limited to 'app/controllers')
| -rw-r--r-- | app/controllers/vehicle_translations_controller.rb | 26 |
1 files changed, 20 insertions, 6 deletions
diff --git a/app/controllers/vehicle_translations_controller.rb b/app/controllers/vehicle_translations_controller.rb index 0eeb450b8..65a0db7fe 100644 --- a/app/controllers/vehicle_translations_controller.rb +++ b/app/controllers/vehicle_translations_controller.rb @@ -8,19 +8,33 @@ 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) - flash[:notice] = "mokmlklmk" + @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 - @vehicle_translation = VehicleTranslation.new( params[:vehicle_translation].merge( :vehicle_journey_id => parent.id)) - @vehicle_translation.translate - flash[:notice] = t('vehicle_translations.success', :count => @vehicle_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 render :action => :new |
