# Exporting table data as a html file

**URL:** <https://www.ruby-forum.com/t/exporting-table-data-as-a-html-file/185821>\
**Category:** Rails\
**Created:** [March 26, 2010, 5:44pm UTC](https://www.ruby-forum.com/t/exporting-table-data-as-a-html-file/185821 "2010-03-26T17:44:02Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![gautam](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/7ab992/32.png) [@gautam](https://www.ruby-forum.com/u/gautam)\
**Post date:** [March 26, 2010, 5:44pm UTC](https://www.ruby-forum.com/t/exporting-table-data-as-a-html-file/185821/1 "2010-03-26T17:44:02Z")

</div>

I have a model named “notice.rb” with a corresponding controller  
“notices\_controller.rb” and my db table “notices” contains two text  
fields - title and body.

I want to save this table data as an html file in a external  
directory. Please help me and suggest me ways to do it. NB: This html  
file is not the view corresponding to this model but it should be a  
different “html file”. You can say that its like exporting data in  
html format.

Here is my code for the model and controller…

#notices\_controller.rb  
class NoticesController \< ApplicationController  
before\_filter :login\_required

def new  
end

def create  
@notice = Notice.new(params[:notice])  
@notice.save  
flash.now[:notice] = “Notice created successfully”  
render :action =\> ‘show’  
end

def show  
@notice = Notice.find(:all)  
end  
end

#notice.rb  
class Notice \< ActiveRecord::Base  
belongs\_to :user

validates\_presence\_of :title, :body  
attr\_accessible :title, :body  
end
