Bob Showalter

Joined

20 Experience
0 Lessons Completed
0 Questions Solved

Activity

Chris, great stuff, thanks. Note that \w in a regex *is* a character class, so it does not need to be enclosed in the [ ] brackets if it's by itself. So /@(\w+)/ is all you need. Also, this would need some tweaking to avoid matching the domain name of an email address, for example. (html-pipeline's version does this)

Posted in Dynamic Active Record Associations?

The price is an attribute of the relation between Event and EventType. has_and_belongs_to_many doesn't allow you to add attributes, so you need to create a full model to hold the relation. I don't know what to call it; maybe just EventPrice.

So:

  • Event has_many :event_prices
  • EventPrice belongs_to :event
  • EventType has_many :event_prices
  • EventPrice belongs_to :event_type

price is then an attribute of the EventPrice model.

You can use has_many :through to reach through Event to EventTypes (and vice versa) if you need to.