rubyonrailsin

A Ruby and Rails talk

Friday, March 26, 2010


[Rails] exporting table data as a html file

by rubyonrailsin 0 comments

Tag


Share this post:
Design Float
StumbleUpon
Reddit

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

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

No comments:

Post a Comment

Subscribe feeds via e-mail

Blog Archive