In my index action I am creating an instance variable like so:
def index
@cards = Card.where(:cardstack_id => params[:cardstack_id])
end
This creates the output for @cards:
[#<Card id: 3, header: "Crazy", body: "Lege deinen Kopf für zwei Minuten auf den Tisch un...", points: 1, cardstack_id: 1, created_at: "2017-06-09 16:41:09", updated_at: "2017-06-13 17:24:29", lifetime: 240>, #<Card id: 4, header: "Böse Zungen", body: "Sprich 20 Minuten in einem starken Dialekt, der un...", points: 3, cardstack_id: 1, created_at: "2017-06-09 16:42:11", updated_at: "2017-06-13 17:26:24", lifetime: 360> ...
What I want to do now is to add for each object a random token created with SecureRandom.uuid
.
So my output should look like this:
[#<Card id: 3, header: "Crazy", token: "34985jlskd908tjkls980", body : "..." ...]
How can I achieve this? I guess I have to somehow loop through the array in my controller, create a token for each element and then add it to a new array. However, I don't know how to achieve this.