I come from a Java background, and am very used to wrapping code into objects.
I was working on my first rails application; while writing up the controller, I wanted to wrap a snippet of code that adapted input from the view and modified it to a format that is accepted by the backend.
I was unsure on where to position these objects. Should this “Adaptor” object I created go into the models? (I tried putting it there, but I cannot manage to find a reference to the file using “require”.)
Thanks!
EDIT
For example, say my input was a date in a string format: “31st July” -> my controller would be:
def create
adaptor = Adaptor.new
date = adaptor.to_date(params[:date])
...
end
Where would the adaptor live? And if this object were to be “common” code, could it be used by my models?
This is presumably a helper object, and should then go into the helpers folder. It is also possible that this should be part of the model. You should read a bit about the “Fat Model, skinny controller” strategy.
A quick google brought these up:
devinterface.com
goodcoresoft.com