Skip to content

Instantly share code, notes, and snippets.

@rubyist
Created March 23, 2011 15:12
Show Gist options
  • Select an option

  • Save rubyist/883257 to your computer and use it in GitHub Desktop.

Select an option

Save rubyist/883257 to your computer and use it in GitHub Desktop.
Thing Model
<% form_for Thing.new do |f| %>
<%= f.text_field :combined %>
<input type="submit" value="Create" />
<% end %>
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