app/controllers/trainings_controller.rb
# Use a training with all its details as a model for a UserTraining (POST only).
#
# == Params:
#
# - <tt>:id</tt> =>
#   The id of the Training; all its details will be retrieved also.
#
Use a training with all its details as a model for a UserTraining (POST only).
Params.

:id =>
The id of the Training; all its details will be retrieved also.
Use a training with all its details as a model for a UserTraining ( POST only ) . Params . : id = > The id of the Training ; all its details will be retrieved also .
def create_user_training
    if request.post?
      training_rows = TrainingRow.where( training_id: @training.id )
      user_training = UserTraining.new()
      user_training.description = "#{@training.title}, #{Format.a_date(Date.today)}"
      user_training.user_id = current_user.id
      begin
        if user_training.save!
          training_rows.each { |training_row|
            user_training_row = UserTrainingRow.new(
              training_row.attributes.reject{|e|
                ['id','lock_version','created_at','updated_at','training_id'].include?(e)
              }
            )
            user_training_row.user_training_id = user_training.id
            user_training_row.save!
          }
          flash[:info] = I18n.t('user_trainings.training_created')
          redirect_to( edit_user_training_path(user_training) ) and return
        end
      rescue
        flash[:error] = "#{I18n.t('trainings.something_went_wrong_during_copy')}"
        redirect_to( trainings_path() ) and return
      end
    else
      flash[:error] = I18n.t(:invalid_action_request)
      redirect_to( trainings_path() ) and return
    end
  end
def create_user_training if request . post? training_rows = TrainingRow . where ( training_id : @training . id ) user_training = UserTraining . new ( ) user_training . description = "#{@training.title}, #{Format.a_date(Date.today)}" user_training . user_id = current_user . id begin if user_training . save! training_rows . each { | training_row | user_training_row = UserTrainingRow . new ( training_row . attributes . reject { | e | [ 'id' , 'lock_version' , 'created_at' , 'updated_at' , 'training_id' ] . include? ( e ) } ) user_training_row . user_training_id = user_training . id user_training_row . save! } flash [ :info ] = I18n . t ( 'user_trainings.training_created' ) redirect_to ( edit_user_training_path ( user_training ) ) and return end rescue flash [ :error ] = "#{I18n.t('trainings.something_went_wrong_during_copy')}" redirect_to ( trainings_path ( ) ) and return end else flash [ :error ] = I18n . t ( :invalid_action_request ) redirect_to ( trainings_path ( ) ) and return end end
Use a training with all its details as a model for a UserTraining (POST only).
Use a training with all its details as a model for a UserTraining ( POST only ) .