David-
While the requirements of the system seem a bit odd (you can run CGI
on the server, but not a sqlite server?), I will give you my best
answer.
Assuming the posts are moderately lengthed....
line_array = []
file.each_line { |line| line_array << line }
title = line_array[0]
date = line_array[1].to_date
contents = line_array[2, line_array.length]
and, viola.
Though, now that I''ve answered the question, besides the db,
I''d
highly suggest using YAML to write the files. It takes up a few more
lines, but is much easier to use in your code.
Just create a class....
class Post
attr_reader :subject, :date, :contents
attr_writer :subject, :date, :contents
end
Then, put some values in...
post = Post.new
post.subject = "Hello!"
post.date = "Tuesday"
post.contents = "Blah, blah \n blah"
Then, you can say...
post.to_yaml
and magically you will have a string you can write out to file that is
a serialized version of the object.
The above example outputs this...
--- !ruby/object:Post \ncontents: |-
Blah, blah
blah
date: Tuesday
subject: Hello!
The advantage of this is that we can then do...
post = YAML.load(@file_object)
And, tada! We have instantly gained back the object that we had
written down to file.
Hope this helps!
-hampton.
On 6/16/06, David R. <davidr64@gmail.com> wrote:> I need to create a news posting system without the use of a database.
I''m
> going to create a file for each news post and have the view post each file
> in a specific directory as HTML.
>
> The newspost will contain:
>
> 1. A title.
> 2. A date.
> 3. The body.
>
> In the text file, I want line 1 to be the title, line 2 to be the date, and
> everything from line 3 on down to the be the body.
>
> What method (so far I know File.each_line lets me read each line) would I
> use to select a specific line in the text file?
>
> Thanks,
> David
>
> _______________________________________________
> Rails mailing list
> Rails@lists.rubyonrails.org
> http://lists.rubyonrails.org/mailman/listinfo/rails
>
>
>