This is probably a total noob question, but I can’t figure it out from
any of my available resources…
I’m trying to move some code into the model. I want to fetch a row
from the database, modify some of the contents, return the modified
version to the controller, WITHOUT saving the changes to the DB. The
reason behind this is that I have some status fields in the DB that
equate to words… rather than save strings in the DB, I figured I
would make the columns tinyints, and then change “1” into “Order
pending processing,” “2” into “Order entered production,” “3” into
“Production complete, awaiting QC,” and so on.
So in my controller I have:
@order = Order.get_formatted_order(params[:id)
and in my model I have:
def self.get_formatted_order(id)
@order = Order.find(id)
end
This works fine and returns the array to the controller, duh. But
whenever I try to tinker with the contents, wierd things happen.
First I tried to just replace one element in the array for fun:
def self.get_formatted_order(id)
@order = Order.find(id)
@order.status = “In Production”
end
And the odd thing to me is that this only returns “In Production” not
the whole array. So then I figured I would get smart…
def self.get_formatted_order(id)
@order = Order.find(id)
self.status = “In Production”
end
This gets me a “undefined method status
…” In desparation I tried
self[:status] and @order[:status] and get variations of the same two
problems.
So how can I pull a row into an array, muss with it, and return the
whole thing to the controller without saving it back to the DB?
Thanks in advance!