(First, I’m very new to Rails and still slightly new to Ruby. So bare
with me.)
I made a Ruby application that allows me to view local XML files which
contain information on my favorite movies. My program reads the XML
files and loads them into variables (such as @title = "The Terminator,
@year = “1984”, etc). All of this is done in a class called Movie, so I
get all the XML files from a directory, then create an array of Movie
classes which all hold the information for their specific XML file.
(For the visual thinkers, that’s: my_dir.each { |i|
my_array.push(Movie.new(i)) })
Everything works fine, and I can organize the data however I please.
But now that I’m getting started with Rails, I’d like to create a
controller that – instead of displaying the movie information to the
console – would write these variables into a SQLite3 database. I’ve
looked around, and I’ve already got the database set up, and with
Scaffolding, I can add/edit/remove entries manually, but I’m still
unsure of how to:
- Copy/paste my Ruby code into my Rails project. (Does the class I’ve
created simply go into a new controller, or is there some other
convention for where to put complete Ruby classes?) - How to add the variables directly to the database, so I don’t have to
manually enter the data.
If anyone could help me with this, I’d greatly appreciate it. If you’re
curious as to my level of knowledge in Rails, the only things I have a
fairly good grasp on are: how to start a server, how to view the pages
on the server, how to create a database (with all the tables I need),
how to create a scaffolding, and what the difference is between
controllers and the actual view page.