1

I'm learning RoR and I've completed a basic course where I made an application that interacts with a database to store user and other model object data.

Now I'd like to create a simple app where the user enters a keyword into a form, the app pulls info about that keyword from a third party api, and then displays the returned data to the user.

I don't need to persist any of the data for later use. I just want to display it immediately when the form is submitted? Can I create a model class that doesn't interact with the database?

As a disclosure, my understanding of persistance comes from iOS development. I need to persist data if the user needs access to that data in a future session. I don't quite yet understand how data can be stored on the web without a db temporarily for the current session.

mnort9
  • 1,810
  • 3
  • 30
  • 54

1 Answers1

2

No, you don't need to use a db if you don't need it. However, keep in mind that Rails is vert tied with the idea of database and ActiveRecord.

If you don't want to use a database, then you should edit the file application.rb generated automatically and change the line

require 'rails/all'

to require only the frameworks you need.

# require 'rails/all'
# require 'active_record/railtie'
require 'action_controller/railtie'
require 'action_mailer/railtie'
# require 'active_resource/railtie'
require 'rails/test_unit/railtie'
require 'sprockets/railtie'

As you can see, I commented out active record and active resource. In this way, Rails will not include ActiveRecord and it won't complain if you skip the database creation.

You can persist data using sessions. However, sessions are limited in size because they are normally stored with cookies. It works well for small IDs or primitive variables, it doesn't work very well for complex data.

As a side note, if you need a simple framework without all the constrains of Rails, you should give Sinatra a try.

Simone Carletti
  • 173,507
  • 49
  • 363
  • 364