How to generate CSV files in Rails
Controller code :
@customers=CustomerInformation.find(:all)
report = StringIO.new
CSV::Writer.generate(report, ,) do |title|
title << [Id, Title, Job Title, First Name, Last Name]
@customers.each do |c|
title << [c.id, c.title, c.job_title, c.first_name, c.last_name]
end
end
report.rewind
send_data(report.read,:type => text/csv; charset=iso-8859-1; header=present,:filename => report.csv, :disposition =>attachment, :encoding => utf8)
end
View
your view will look like
how can we apply validation to image uploading file…
Hello Mr. verma
What type of validation you want ?
for type use
validates_format_of :picture, :with => %r{\.(gif|jpg|png)$}i,
:message => “must be a URL for a GIF, JPG, or PNG image”
for size use
validates_size_of :picture, :maximum =>
If your problem is somthing else, let me know the problem
or you can use file_column plugin
hai satish, thank for your fast replay
i am using file_column plugin in my application, for uploading image file to database.when i am uploading the image file to database without any imagepath(i.e empty ) in the upload field its getting error as:
undefined method `read’ for “”:String
i want to display the validation message rather than displaying the error message, for my application.so what type of validations i have to apply to my image uploading please can u suggest any thing more….
dear
file_column did not store file in database , it store its name only
use
{:controller=>”controller_name”, :action=>”action_name”}, :html => { :multipart => true } do |f| -%>
look at html options include :multipart=>true
hope this will definitely solve your problem