Monday, April 11, 2011

Dungeon Roller progress

So I'm not entirely at a loss here. I've got the main Character model and three other models associated with Character: Statistic, Safe and Combat. Here's what the Character screen looks like:


Once you click through on a character, this is what you see:


Now say you want to click through on Statistics:


But here's the problem. The individual characters are all using the same instance of the Statistic model. I haven't worked with the other models yet, but I'm assuming this would be true for them as well. How do I need to edit the code so each Character has a separate Statistic, instead of the same Statistic being shared?

Here's my code from the routes.rb file:

DungeonRoller::Application.routes.draw do
  resources :combats

  resources :saves

  resources :statistics

  resources :characters do
    resources :combats
    resources :saves
    resources :statistics
  end

And some code from the models:

class Character < ActiveRecord::Base   has_many :statistics   has_many :combats   has_many :saves end And each of the other models have: class Statistic < ActiveRecord::Base

  belongs_to :character

end

I thought associating these as has_many would solve the problem, but apparently I was wrong. Any input on this would be greatly appreciated!

2 comments:

  1. All the code you pasted looks fine. I think the problem lies in how you're interacting with statistics. Make sure you're using @character.statistic instead of Statistic, this will automatically scope it to that character's statistic instead of ALL statistics.

    ReplyDelete
  2. @Eli I haven't checked through this code since I've been working through Agile Web Development, but I'm sure you're right. The funny thing is, I knew it was something along those lines but didn't know how to express that feeling or how to go about solving it. Soon enough!

    ReplyDelete