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

Snippets has posted 5883 posts at DZone. View Full User Profile

Save Text Page As A File

  • submit to reddit
        // 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]
		# Get comment for each post 
		url = URI.parse('')
		@res = Net::HTTP.start(, url.port) {|http|
	content =
	name =
	docs =
	# content of the comment
	docs.elements.each("*/entry/content"){ |element| 

		if element.text == nil or element.text == ""
			content << 'No comments yet for this post'
                    content << element.text
	docs.elements.each("*/entry/author/name"){ |element|  
		if name.include?("#{ element.text}") == false
		name <<  element.text  
	@author = name
	@comment = content
	@author_says = "#{@author} Said:"
	render :action => :view_each_posts