Génération aléatoire de doc et vue.

Bonjour à tous, je suis tout nouveau, français et prof de maths… Je débute donc avec ROR.

Je génère aléatoirement des exercices de maths avec des variables dans mon controller show, puis à l’aide d’un helper, je les affiche dans ma vue show.

Mais comme il y a plusieurs exercices générés comme cela ( exo1, exo2, exo3), cela me donne les variables @exo1, @exo2, @exo3. et donc 3 vues, 3 controller, et 3 modèls !

Comment dois je m’y prendre pour n’utiliser qu’une seule vue show ? Je pense qu’il faut quand même 3 helper et 3 controller ? Pour les model, ils sont identiques. Puis je n’en avoir qu’un seul ?

Merci pour votre aide.

I hope you can read English, since I can still read French but writing it is very slow for me.

I am unclear: do you want 3 exercises shown together on a single page, or separate pages which the user accesses one after the other but using the same controller?

Je suis en dernière année d'informatique et pratique le ruby depuis quelque mois ( 2-3 ) ... Ma réponse n'est donc pas une vérité absolue surtout qu'elle est intuitive

mais comme ca je dirais qu'il suffit de placer tes variables dans un Array ;

@MesExercices = Array.new @MesExercices.push(exo1) @MesExercices.push(exo2) @MesExercices.push(exo3) . . .

puis dans la vue faire quelque chose comme cela

<% for unExercice in @MesExercices %>   # Do whatever you want to ‘unExercice ’   expl :<label> <% unExercice.titre %> </label> <% end %>

voilà , c'est ma première réponse sur le forum donc n'en demande pas trop :stuck_out_tongue: en espérant avoir aidé ... bye Tanguy.

Ces 2 types d'exercices peuvent ils être dans le même model ?

I believe so, however I have no experience in this specific domain. Just a suggestion, I assume you already have some way to represent a formula in the database, so perhaps you could have an attribute specifying whether coefficients are fixed, or to be varied. (Or even allow it to be specified per-coefficient.)

So in that case, your model logic for fetching, validation, and so on, would have to take into account which coefficients to assign a varying value (and when).

It seems to me that a view would receive a model object with coefficients already specified, and would have no need to know whether the coefficients are fixed or not, so the view code would not change. Similarly, the controller would depend on the model for initialization before sending to the view, and validation on submission, so could be the same code in either case.

It's also possible to consider using inheritance, a base class for the common logic, and inherited classes with specific overrides. RoR has facilities for dealing with this. I personally don't think it's needed here; I mention it only because I don't know the details of your model representation, so it's possible that inheritance is more appropriate to your needs than I realize.

Suis je clair ?

I think so. It seems to me your problem is more with representation of the underlying model, and that any RoR questions you may have other than creating the mode will be relatively simple.