Saturday, April 9, 2011

Model misbehavior

I've been trying to get a handle on models and associating them with other models this weekend. Here's what's going on:

I'm working on Dungeon Roller and I've created two models: Character and Statistic. What I want to do is have Statistic display under Character. So logically I need to associate these models such that Character has_one Statistic model and Statistic belongs_to Character, right? These associations (has_one, has_many, belongs_to and has_and_belongs_to_many) all refer to how many of those models can display the model they're associated with, right?

If I can get this relationship figured out, and make it so that Statistic will display on Character and remain separately editable, I can use that as a template to hammer out other models I've got planned. I'll eventually have 7 or 8 models that belong to the main Character model. I ran into some trouble earlier when I named Character as Characters, not realizing that is not the way to do things. I also ran into some trouble with reserved keywords. I had "class" as a string in the Character model and eventually figured out I couldn't use it.

So while today's been frustrating because I haven't made as much progress as I'd like to, I got those two things figured out at least.

Thursday, April 7, 2011

More on Dungeon Roller

Here's a little update on Dungeon Roller.

For a while I was stuck on how to manipulate models and put them where I want them to go. For example, I have a Characters model, which will contain separate characters. Each character will have other models associated with it, such as statistics, weapons, armor, skills, etc. But I think I've got this hammered out. It's just a matter of linking to the relevant models in the relevant places, right?

I've found a few differences between working with Rails and working with Ruby. I find time goes by a lot faster when I'm working with Rails. I'm not sure if this is because now I finally have a real project and it's more fun than learning more abstract things or if it's because I prefer working with Rails to working with Ruby.

I've had to scrap my work on Dungeon Roller twice now and start over (due to screwing up the code and not knowing how to fix it) but I have a good feeling about this third attempt! I'm really looking forward to putting some serious time in this weekend and getting a workable version hammered out.

One of the beautiful things about the internet is whenever Rails barfs on my code, I can just google the error and find a solution. Still, I really need to look into getting my mitts on a Beginning Rails book. I've got one reserved at the library, but some other nerds are sitting on the only three copies in Indianapolis. Give it up, nerds!

Sunday, April 3, 2011

Working on Dungeon Roller

I began work on Dungeon Roller (working title) tonight. I'm using the blog tutorial from rubyonrails.org as a guide. The idea is pretty similar and the functionality seems like it will overlap enough that I can just edit the code where needed.

So here's what I'm working with so far: I've generated the main Character model and I want other models to be associated with it and displayed when viewing a Character, but I want them to remain separately editable. Under the Character model, I've got strings for Name, Class and Level and Text for Background and Description. These should be fairly static, but users will still be able to edit as needed.

I plan to make separate models for Stats, Skills and Equipment, all of which will be visible from the Character model, but remain separately editable. Am I making sense here?

Some questions:

So far, I don't require creating an account/username before creating characters. This is definitely something I'll want in the future, but for developing purposes it seems too clunky to add now. How easy is this to add later? Should I even be worried about that right now?

When generating a model, how difficult is it to add or delete multiple items from that model? I'm assuming there's a command for it, but haven't run into it yet.

I'm pretty excited about this project. It feels good to have a concept and to figure out ways to make it work!