0

I am showing some properties of an ActiveRecord::Base called Micropost:

<table>
  <tr>
    <th>Items</th>
    <th>Creation Date</th>
    <th>Progress</th>
  </tr>

  <td>
    <% @user.microposts.each do |micropost| %>
    <tr>
      <td><%= micropost.content %></td>
      <td><%= micropost.created_at %></td>
      <td><%= micropost.progress %></td>
    </tr>
    <% end %>
  </td>
</table>

This is the class definition:

class Micropost < ActiveRecord::Base
  belongs_to :user
  validates :content, length: { maximum: 140 }
  @progess = 0
end

It works fine if I don't put the <td><%= micropost.progress %></td>. However, if I do I get a:

undefined methodprogress' for #`

I have also tried progress :number but I can't quite seem to find out how I can add a variable to that class and display it on my .erb.

1 Answer 1

1

@progress = 0 sets a class-level instance variable and does not create any methods. To create instance methods, use def, or one of attr_accessor, attr_reader, or attr_writer.

Sign up to request clarification or add additional context in comments.

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.