tag:blogger.com,1999:blog-6793817269158736634.post26255190419709465..comments2023-07-11T06:44:05.157-07:00Comments on Code It Like You Stole It: WTF is an attributeTylerhttp://www.blogger.com/profile/02372203985854517525noreply@blogger.comBlogger2125tag:blogger.com,1999:blog-6793817269158736634.post-54889881378357708152011-05-20T09:15:09.640-07:002011-05-20T09:15:09.640-07:00Yeah, the main problem with old tutorials is often...Yeah, the main problem with old tutorials is often the syntax will be slightly different or they'll be using a different database, but it's easy enough to convert it to what I'm using now. It's pretty painful when the tutorial calls for a PC with a MySQL database and separate program to create tables, though! I'm all "UGH, people did things this way?"<br /><br />This weekend I plan to get used to Git. I feel like I've been bouncing around a lot with my RoR learning, but I don't think that's necessarily a bad thing.Tylerhttps://www.blogger.com/profile/02372203985854517525noreply@blogger.comtag:blogger.com,1999:blog-6793817269158736634.post-39599075830160416522011-05-20T08:32:10.033-07:002011-05-20T08:32:10.033-07:00in Rails, attributes refer to "things that co...in Rails, attributes refer to "things that contain data in models" usually this means columns on persistent storage. Associations are just relationships between these "things that contain data". Try calling attributes on a model to see exactly what data we're talking about.<br /><br />has_one associations are a funny case. Almost always you could put the columns directly on the parent model, instead of the association. Often though, you'll want this data only occasionally, or it needs to have a lot of functionality not related to the parent model, so you break it out into it's own model.<br /><br />As a concerete example, we worked on a web-based game once that had a Character model, and two has_one relationships to Inventory and Population.<br /><br />Population was somewhat bad to be split from Character because we displayed population data very frequently, so adding this extra step of indirection provided little performance benefit but did serve as a nice place to store methods that were specific to Population stats. If I had it to do over, I would have merged this into the Character model.<br /><br />Inventory was used very rarely (only when attacking other users), and it had well over a hundred columns, lots of custom methods for generating attack ratings. It was pretty clear that this model would have been a disaster to merge into character.<br /><br />Many Rails articles are old, but that doesn't always mean they are unusable, just that they are probably doing more work than they would have to for the latest version of Rails.Elijah Millerhttps://www.blogger.com/profile/11416221333112662701noreply@blogger.com