3

On my views I use 1 form that includes a block that renders comments. I do not want to run it when creating a new record. So, I tried conditions like so...

<% unless @annotation_id.nil? %>
<hr>
<div class="row">
  <div class="col-md-8">
    <h4>Comments</h4>
    <%= render @annotation.comments %>
  </div>

  <div class="col-md-4">
    <%= render 'comments/form' %>
  </div>

</div>
<% end %>

This however results in never displaying the block - also when the annotation record exists. What am I doing wrong?

1
  • @annotation_id is not a record. Are you assigning it anywhere? Commented Sep 2, 2016 at 14:31

2 Answers 2

3

You don't show that you have actually set @annotation_id to something.

A simpler way might be to use the .new_record? method instead, like:

<% unless @annotation.new_record? %>
  ...
<% end %>
Sign up to request clarification or add additional context in comments.

Comments

0

use if @annotation.persisted? or unless @annotation.new_record?

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.