This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Wrong! | |
| # If foo is valid but bar is not, foo is still saved. | |
| # This breaks the transactional nature | |
| # | |
| def create | |
| Foo.transaction do | |
| @foo = Foo.create(params[:foo]) | |
| @bar = Bar.create(params[:bar]) | |
| if @foo.save and @bar.save | |
| redirect_to some_url |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| for i in $(find db/migrate |grep mondrian |cut -d '/' -f 3 | cut -d '_' -f 1 ) | |
| do | |
| rake db:migrate:down VERSION=$i | |
| rake db:migrate:up VERSION=$i | |
| done | |
| rake mondrian:init |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Device | |
| validates_uniqueness_of :device_number, :scope => :customer_id | |
| after_create: assign_device_number | |
| def assign_device_number | |
| begin | |
| device_number = self.customer.devices.map(&:device_number).compact.max) || 0 + 1 | |
| save! | |
| rescue Whatever gets thrown for validation error |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Device | |
| # ... | |
| def friendly_name | |
| "#{self.customer.device_name_prefix} #{self.device_number}" | |
| end | |
| end |
NewerOlder