views:

162

answers:

4

I have a small ruby application that I made on my local machine. It uses a text file insted of a database. It's a simple app that takes in a word, processes it against the text file, and then outputs the results using puts.

I would like to fit it into a RoR framework, hosted on my personal machine. I have run through some lessons and tutorials in a few books and online materials I have, but they all involve databases.

I read thru the notes in config/environment.rb and found at line 19 instructions to uncomment the line that removes ActiveRecord.

I am currently looking for the appropriate directories to put the text file itself, and the code from the ruby app that reads this text file. Thank you.

+2  A: 

This sounds like a better fit for something more lightweight like Sinatra.

If you were bound and determined to use Rails, you could make a controller with an action that just runs the code from your program, but it seems like overkill. You wouldn't be using 99.9% of the framework's capabilities, so why is it even there?

Chuck
I am going to go back and check out Sinatra. I am using rails because my hosting Service knows how to deploy and it's just temporary. thanks for the tip on Sinatra though, it looks interesting.
cloudhead
Definate Sinatra candidate.
railsninja
+2  A: 

You probably want to do something like the following:

  • Have a controller that takes the word as a parameter.
  • Turn you app into a function that takes the word as a parameter and returns the results (instead of doing puts)
  • Call the function from your controller and render the results (e.g. something like:

    render :text => my_func(word)

MarkusQ
+1  A: 

If your just trying to give it a little interface you could look at Shoes which is an easy to use multi-platform gui framework.

Or like someone mentioned take a look at Sinatra.

You can simply use rails without worrying about ActiveRecord. I'd sugest making your little application into a class and requiring the file in a controller you want to use (or in environment.rb). Put the file in lib and if the data is temporary, "tmp" is fine or just put it in "lib" with the script you wrote even "db" is a fine location for it. To make a view just run your code and put the return in a class variable and make a view for it.

nkassis
A: 

A model need not inherit from ActiveRecord::Base. Or anything else. As long as it follows the naming convention for models, Rails will pick it up without problem.

Having said that, if you're really looking at a one-model, one-controller, one-action, no-database app, then Sinatra would probably be a really good lightweight place to start...

Mike Woodhouse