N
N
N. Bekseitov2015-02-04 13:08:49
Ruby on Rails
N. Bekseitov, 2015-02-04 13:08:49

What is the correct way to store data in a Postgresql array?

Hi all. There is a Students model and a balance field, where, using a pop-up window, I add money to the student's account. I need to create a "payments" page where all the payment information of the current student will be stored. I created the page and tried to store information in the payment array. The problem is that only 1 last value is added to the array. Postgresql
Controller database

def payment
@student = Student.find(params[:id])
@history = @student.add_payment
end

Model
attr_accessor :money

 def add_money
self.balance += @money.to_i
self.money_new += @money.to_i
end 

def add_payment
  self.payment = []
  self.payment.push(self.money_new)
end

view
<%- model_class = Student -%>
<div class="page-header">
<h3>История платежей</h3>
</div>
<table class="table table-striped">
<thead>
<tr>
<th>Сумма</th>
</tr>
</thead>
<tbody>
  <% @history.each do |i| %>
    <tr>
      <td><%= i %></td>
    </tr>
   <% end %>
</tbody>
</table>

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Viktor Vsk, 2015-02-04
@nbekseitov

I do not understand what you are doing, but the problem
when calling a method
, lies here:
That is, you first create a new array, and then add something there. Naturally, this something will be there in splendid isolation.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question