Forum: Ruby on Rails Where do i put the code to pull data from an API?

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
A42d36584629c6facec2a4803c886fad?d=identicon&s=25 Koalemos (Guest)
on 2007-08-02 05:47
(Received via mailing list)
My app doesnt use a database, it gets all it's information from an
api. I was wondering whether i should put the code for pulling the api
data into an array in the controller or a model?

This is a pretty simple app right now with only one controller, I may
expand it later but I have no plans to do so right now.
3f38541776a2513a20ea2f1c2d522cb3?d=identicon&s=25 Perry Smith (pedz)
on 2007-08-02 06:06
Koalemos wrote:
> My app doesnt use a database, it gets all it's information from an
> api. I was wondering whether i should put the code for pulling the api
> data into an array in the controller or a model?
>
> This is a pretty simple app right now with only one controller, I may
> expand it later but I have no plans to do so right now.

I'm curious what others say.  I'm going to be in the same boat in a few
days.  But it sounds like a model to me.  The API to fetch the data is
logically the same as the API to the database methods to fetch the data.

Thats my thought anyway.
B01fdd12039d82427a4af02360ef5571?d=identicon&s=25 cammo (Guest)
on 2007-08-02 07:01
(Received via mailing list)
In the model,
All your data objects should be in the models, and the controller is
simply a bridge between the models and the views, pooling out only the
data the view needs, so you'd write methods for retrieving and
creating data in your model and then call those functions in your
controllers and parse those arrays etc into your views.

Cam
9a71df6388c8d37bfdf0e18742ea944a?d=identicon&s=25 AndyV (Guest)
on 2007-08-03 19:50
(Received via mailing list)
Definitely in a model.  Here's the Rails hint: ActiveResource::Base
(edge/2.0) is similar to ActiveRecord::Base.
This topic is locked and can not be replied to.