Created
March 23, 2011 15:12
-
-
Save rubyist/883257 to your computer and use it in GitHub Desktop.
Thing Model
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
| <% form_for Thing.new do |f| %> | |
| <%= f.text_field :combined %> | |
| <input type="submit" value="Create" /> | |
| <% end %> |
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 Thing < ActiveRecord::Base | |
| def combined=(data) | |
| self.number, self.subtype = data.split('-') | |
| end | |
| def combined | |
| if self.number.present? && self.subtype.present? | |
| "#{self.number}-#{self.subtype}" | |
| else | |
| "" | |
| end | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment