File tree Expand file tree Collapse file tree 5 files changed +28
-1
lines changed
Expand file tree Collapse file tree 5 files changed +28
-1
lines changed Original file line number Diff line number Diff line change 11class TransfersController < ApplicationController
22 def create
33 @source = find_source
4- Transfer . create ( transfer_params . merge source : @source )
54 @account = Account . find ( transfer_params [ :destination ] )
5+ transfer = Transfer . new (
6+ transfer_params . merge ( source : @source , destination : @account )
7+ )
8+
9+ if transfer . valid?
10+ transfer . make_movements
11+ else
12+ flash [ :error ] = transfer . errors . full_messages . to_sentence
13+ end
614 redirect_to redirect_target
715 end
816
Original file line number Diff line number Diff line change @@ -17,6 +17,8 @@ class Transfer < ActiveRecord::Base
1717 belongs_to :operator , class_name : "User"
1818 has_many :movements
1919
20+ validate :different_source_and_destination
21+
2022 after_create :make_movements
2123
2224 def make_movements
@@ -39,4 +41,9 @@ def source_id
3941 def destination_id
4042 destination . respond_to? ( :id ) ? destination . id : destination
4143 end
44+
45+ def different_source_and_destination
46+ return unless source == destination
47+ errors . add ( :base , :same_account )
48+ end
4249end
Original file line number Diff line number Diff line change 102102 attributes :
103103 web :
104104 url_format_invalid : Format de URL no vàlid
105+ transfer :
106+ attributes :
107+ base :
108+ same_account : No es pot fer una transacció al mateix compte
105109
106110 # ETIQUETAS VARIADAS EN PLANTILLAS
107111
Original file line number Diff line number Diff line change 102102 attributes :
103103 web :
104104 url_format_invalid : invalid URL format
105+ transfer :
106+ attributes :
107+ base :
108+ same_account : A transfer cannot be made to the same account
105109
106110 # ETIQUETAS VARIADAS EN PLANTILLAS
107111
Original file line number Diff line number Diff line change 102102 attributes :
103103 web :
104104 url_format_invalid : Formato de URL no válido
105+ transfer :
106+ attributes :
107+ base :
108+ same_account : No se puede hacer una transacción a la misma cuenta
105109
106110 # ETIQUETAS VARIADAS EN PLANTILLAS
107111
You can’t perform that action at this time.
0 commit comments