# Newbie question - Rails without database

**URL:** <https://www.ruby-forum.com/t/newbie-question-rails-without-database/55018>\
**Category:** Rails\
**Created:** [March 16, 2006, 10:02am UTC](https://www.ruby-forum.com/t/newbie-question-rails-without-database/55018 "2006-03-16T10:02:30Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![mrkohrea](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/4491bb/32.png) [@mrkohrea](https://www.ruby-forum.com/u/mrkohrea)\
**Post date:** [March 16, 2006, 10:02am UTC](https://www.ruby-forum.com/t/newbie-question-rails-without-database/55018/1 "2006-03-16T10:02:30Z")

</div>

Hello to all,

I am entirely new to Ruby and also to Ruby on Rails. As far as I  
understand,  
Rails builds its model according to the a specified table structuree in  
in the  
database.

However, most of my applications, are for the most part (except some  
backend  
CRUD stuff) not database centric. They do a lot of calculation for the  
user.

So, how can I create a model, when no database is needed, and yet, have  
it  
running on the Rails framework?

Greetings

Michael K.

---

<div class="post-metadata">

**Author:** ![mrkohrea](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/4491bb/32.png) [@mrkohrea](https://www.ruby-forum.com/u/mrkohrea)\
**Post date:** [March 16, 2006, 10:08am UTC](https://www.ruby-forum.com/t/newbie-question-rails-without-database/55018/2 "2006-03-16T10:08:46Z")

</div>

You pretty much inferred your own answer - you don’t need a model. JUst  
create a controller to do the math and a view to display.

Geoff

---

<div class="post-metadata">

**Author:** ![mrkohrea](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/4491bb/32.png) [@mrkohrea](https://www.ruby-forum.com/u/mrkohrea)\
**Post date:** [March 16, 2006, 10:33am UTC](https://www.ruby-forum.com/t/newbie-question-rails-without-database/55018/3 "2006-03-16T10:33:24Z")

</div>

Well, I wasn’t very specific.

actually, what I mean is a very simple two step workflow.

The user is requierd to fill in a form with a number of fields. After he  
has  
submitted the form, the data is being evaluated.

If errors occur the user is returned to the initial form. Otherwise he  
proceeds  
to the next form, where he is once again required to enter some more  
data,  
depending on the result.

And then the final calculation step, again with some calculation, takes  
place.

For the duration of the session, there is a model on the web server for  
backing  
up of the form data.

Eventually the resulting data is being processed for pdf generation. But  
there’s  
no persistence taking place.

Is there a way Rails can still automatically match my form data with the  
model  
and evaluate it?

Sincerely

Michael K.

---

<div class="post-metadata">

**Author:** ![mrkohrea](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/4491bb/32.png) [@mrkohrea](https://www.ruby-forum.com/u/mrkohrea)\
**Post date:** [March 16, 2006, 12:59pm UTC](https://www.ruby-forum.com/t/newbie-question-rails-without-database/55018/4 "2006-03-16T12:59:30Z")

</div>

On 3/16/06, Michael K. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> So, how can I create a model, when no database is needed, and yet, have it  
> running on the Rails framework?

Just try creating your model classes by hand, instead of using the  
`generate’ script. Rails can do some object-relational mapping work  
for you if a database is in use, but if you don’t need one, you can  
choose not to use it. Just make sure to not subclass  
ActiveRecord::Base on your model classes.

Cheers,

Thiago A.

---

<div class="post-metadata">

**Author:** ![mrkohrea](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/4491bb/32.png) [@mrkohrea](https://www.ruby-forum.com/u/mrkohrea)\
**Post date:** [May 18, 2006, 2:36pm UTC](https://www.ruby-forum.com/t/newbie-question-rails-without-database/55018/5 "2006-05-18T14:36:12Z")

</div>

Thiago A. wrote:

> On 3/16/06, Michael K. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:
> 
> > So, how can I create a model, when no database is needed, and yet, have it  
> > running on the Rails framework?
> 
> Just try creating your model classes by hand, instead of using the  
> `generate’ script. Rails can do some object-relational mapping work  
> for you if a database is in use, but if you don’t need one, you can  
> choose not to use it. Just make sure to not subclass  
> ActiveRecord::Base on your model classes.
> 
> Cheers,
> 
> Thiago A.

…took a long time to reply to this message, but as i am working on  
something simillar to this, i was hoping to see if someone can give me a  
little more informative(for a newbie, yea) information as to using a  
rails app without a database (i need to build a model, and i was told  
not to use activerecord, but from there on, i am in the dark…)  
any help, links, or just general sympathy will be mostly appreciated.

with much thanks,

shai rosenfeld  
newbee employee for Octava IL

---

<div class="post-metadata">

**Author:** ![mrkohrea](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/4491bb/32.png) [@mrkohrea](https://www.ruby-forum.com/u/mrkohrea)\
**Post date:** [May 18, 2006, 2:58pm UTC](https://www.ruby-forum.com/t/newbie-question-rails-without-database/55018/6 "2006-05-18T14:58:19Z")

</div>

Hi Shai,

General sympathy 🙂

Seriously, you’ll have to give more details as to what you want to  
acheive before anyone can help. For example, when you said you need to  
have a model but don’t want to use a database, what do you mean by that?  
How do you want to persist your model? If you don’t want to persist your  
model, then just create any Ruby class, and there you have it. Nothing  
fancy needed. If you want to persist it to the file system, then YAML it  
or work a bit harder to XML it.

shai wrote:

> > choose not to use it. Just make sure to not subclass  
> > little more informative(for a newbie, yea) information as to using a  
> > rails app without a database (i need to build a model, and i was told  
> > not to use activerecord, but from there on, i am in the dark…)  
> > any help, links, or just general sympathy will be mostly appreciated.
> 
> with much thanks,
> 
> shai rosenfeld  
> newbee employee for Octava IL

–  
Sau S.

[http://blog.saush.com](http://blog.saush.com)  
[http://www.projectible.com](http://www.projectible.com)  
[http://jaccal.sourceforge.net](http://jaccal.sourceforge.net)

---

<div class="post-metadata">

**Author:** ![mrkohrea](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/4491bb/32.png) [@mrkohrea](https://www.ruby-forum.com/u/mrkohrea)\
**Post date:** [May 18, 2006, 4:43pm UTC](https://www.ruby-forum.com/t/newbie-question-rails-without-database/55018/7 "2006-05-18T16:43:02Z")

</div>

Hi,

I think you could use the “session” valiable. Basically, it’s a cookie  
where  
you can store specific user info - without actually identifying the  
user.

“session” is a hash table, therefore it seems to make sense to create  
session[:page\_1] = Array.new(), and then to store your questions in this  
array. You do the same for page 2 and so on.  
It could be wiser to create a Hash.new() instead of the Array, becaus  
you  
could insert “meaningful” data, for example a field “valid”. In that  
case,  
you would store the answers like:

session[:page\_1][:question\_1] = @params[:question\_1]  
…  
(if everything OK)  
session[:page\_1][:valid] = true  
…  
then you render page 2. When a page is rendered, you take the answers  
from  
the session valiable, and you are able to go back / forward / repeat  
while  
keeping the values set by the user.

Yu can also remember which page you render, and in that case you  
prpobably  
need only one controller to handle everything (but that’s an other  
story)

Regards

Nicolas
