Note that there are some explanatory texts on larger screens.

plurals
  1. PONeed help with an edit action
    text
    copied!<p>I'm working on a roleplaying game character database app and I need some help.</p> <p>I've got two models, Character and Statistic. Each Character will have one instance of the Statistic model, which is a table with 6 separate statistics. I've used a partial to render the Statistic form on the Character view, so I can create a new Statistic that is associated with that Character from the Character view. However, I can't edit the Statistic and I can generate more than one instance, which are both problems. </p> <p>My questions are:</p> <p>How do I code an edit action in the Statistic controller so that I can edit the instance of Statistic from the Character view? I also want this to over write any Statistic instance that is present, so that I don't end up with multiple sets of Statistics per Character.</p> <p>Thanks!</p> <p>EDIT: Here's some code:</p> <p>From the Statistic controller:</p> <pre><code>def edit @statistic = Statistic.find(params[:id]) end </code></pre> <p>From the Character view:</p> <pre><code>%= render "statistics/form" % </code></pre> <p>And the form this code renders:</p> <pre><code>%= form_for([@character, @character.statistics.build]) do |f| %&lt;br /&gt; div class="field"&lt;br /&gt; %= f.label :strength % &lt;br /&gt; %= f.text_field :strength %&lt;br /&gt; /div&lt;br /&gt; div class="field"&lt;br /&gt; %= f.label :dexterity %br /&lt;br /&gt; /div&lt;br /&gt; div class="field"&lt;br /&gt; %= f.label :constitution %&lt;br /&gt; %= f.text_field :constitution %&lt;br /&gt; /div&lt;br /&gt; div class="field"&lt;br /&gt; %= f.label :intelligence %&lt;br /&gt; %= f.text_field :intelligence %&lt;br /&gt; /div&lt;br /&gt; div class="field"&lt;br /&gt; %= f.label :wisdom %&lt;br /&gt; %= f.text_field :wisdom %&lt;br /&gt; /div&lt;br /&gt; div class="field"&lt;br /&gt; %= f.label :charisma %&lt;br /&gt; %= f.text_field :charisma %&lt;br /&gt; /div&lt;br /&gt; div class="actions"&lt;br /&gt; %= f.submit %&lt;br /&gt; /div&lt;br /&gt; % end %&lt;br /&gt; </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload