DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world
Save Text Page As A File
// description of your code here
I am developing a mobile Application that users can view their Blog
posts and also make posts to their blogs via a mobile phone. I also
want it in such a way that the users can save a particular post of
interest for future references or to read when they are offline. What
I intend doing is to save the post as a text file and save the title,
Author, Date-Published and category in the database. I should also
keep record of the number of entries such that it prompts one to
delete an item if the number of saved items is up to 5. Please can
someone help me with how to go about saving.
// insert code here..
def view_each_post
@id = @params['id']
#to accept the global variable as an instant variable
#@post_id = $post_id
$post_id.each_with_index{ | id, index|
if id == @id
@content = $content[index]
@post_id = $post_id[index]
@published = $published[index]
@category = $category[index]
@post_title = $post_title[index]
end
}
# Get comment for each post
url = URI.parse('http://www.blogger.com')
@res = Net::HTTP.start(url.host, url.port) {|http|
http.get("/feeds/#{$blogID}/#{@post_id}/comments/default")
}
content = Array.new
name = Array.new
docs = REXML::Document.new(@res.body)
# content of the comment
docs.elements.each("*/entry/content"){ |element|
if element.text == nil or element.text == ""
content << 'No comments yet for this post'
else
content << element.text
end
}
docs.elements.each("*/entry/author/name"){ |element|
if name.include?("#{ element.text}") == false
name << element.text
end
}
@id
@content
@post_title
@published
@category
@post_id
@author = name
@comment = content
@author_says = "#{@author} Said:"
render :action => :view_each_posts
end





