0

I have the following code:

UPDATED with correct code:

<div class="field_med" id="ticket_note">
<%= f.fields_for :notes, Note.new do |u| %>
<%= u.text_area :note, :size => "46x4", :placeholder => "Leave notes here. Only Admins can see these." %>
<% end %>
</div>

This has a has_many association to my Ticket model so I can append as many notes as I want.

With the above code, when in my edit view it shows all notes in their own separate textarea that can be editing at the same time.

I'm using the below code to show my preexisting notes in a non-editable format.

<div class="field_med" id="ticket_note">
<% for note in @ticket.notes %><br />
<%= note.created_at %> <%= note.note %>
<% end %>
</div>

How can I just show the latest textarea for a new note, but not display all the preexisting notes?

1
  • Using <%= f.fields_for Note.new do |u| %> actually gives me what I'm looking for. But when I save it, to add the new note I get Can't mass-assign protected attributes: note But I know it's not because of the attr_accessible in either Ticket or Notes model because it saves without issue the original way. Commented Aug 7, 2013 at 6:25

1 Answer 1

1

You could do something like this:

<%= f.fields_for :notes, @ticket.notes.build do |u| %>
Sign up to request clarification or add additional context in comments.

1 Comment

This was close and made me realize I left out the :notes. Duh.

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.