I have a controller
def update
@patient = Patient.find(@score.patient_id)
respond_to do |format|
if @score.update(score_params)
format.html { redirect_to score_path(@score), notice: 'Score was successfully updated.' }
format.json { render :show, status: :ok, location: @score }
else
format.html { render :edit }
format.json { render json: @score.errors, status: :unprocessable_entity }
end
end
end
When a "score" object is edited and passes validations everything is fine.
However (and here is the issue), in a sidebar I have a "current entries for this score" box which essentially shows the current entries for the object.It looks like this:
<div class = "CompletionFrame">
<div class="page-header">
<h4>Your scores for this case</h4>
</div>
</div>
<ol>
<%= @score.exists(@score.dx1, @score.dxcon1) %>
<%= @score.exists(@score.dx2, @score.dxcon2) %>
<%= @score.exists(@score.dx3, @score.dxcon3) %>
<%= @score.exists(@score.dx4, @score.dxcon4) %>
<%= @score.exists(@score.dx5, @score.dxcon5) %>
</ol>
The details of the attributes are not important. What is strange is that if I attempt to update with invalid attributes, the controller renders the edit view but the invalid entries are shown in the "current entries for this score". If I go to another page and then back to this page, then the old (unedited) entries are shown. In other words, the invalid entries are not saved, but they are shown on the initial render :edit call by the controller.
My questions are:
Why is this?
How can I prevent this updating of the sidebar for that single "render"
I hope this makes sense.