Question

Here's a programming challenge I'm facing. I'm new at this...

I'd like to do this the Rails Way, with elegant code, and learn something in the process.

In my app, Players track an Action (25 minutes of focus starting on the half-hour). The action#new form loads at the beginning, but is not saved until the end of the 25 minutes. The last 2 minutes are a retrospective and include some required "how did it go" questions.

I now want to add an Insights table. I'm picturing a separate, small "new Insight" form that blends into the larger "new Action" form. I want to save the Insight at whatever time it comes to me.

I also want the Insight to be associated with that particular Action... even though the Action hasn't been created yet, and I don't know what id it will have (somebody else may record their Action before I do). If an Insight was created but the Action fails, I'm not yet sure what to do... I could allow Action-less Insights.

How do I implement this? A temp variable? Where would that go?

Again, I'm brand new at this, and I appreciate your support.

Mihai TheActionGame.com

Était-ce utile?

La solution

I'm note sure about what your action represent, but even if you have some time-based principle, nothing prevent your for saving the Action before (for a browser-based application, 25 minutes is a lot of time during which a lot of bad things can happen, like a refresh or a connection failure).

My advice would be to create (save) the Action immediately, thus allowing your Insight to be linked to it. I would add a "status" column to Action, with something like "new" (the base status), "confirmed" and other if needed.

You can then work only on the "confirmed" Actions, and eventually delete the "new" one on a regular basis (like all that are older than 30 minutes, with your thresold of 25).

Hope this make sense (more design than Rails, anyway).

Autres conseils

You could add a column to your actions "insight_ids" as an array and implement it as a has_and_belongs_to_many. Then when you have an insight, record the insight's id in the array

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top