On 10 fév, 10:21, "Sergio Cambra .:: entreCables S.L. ::."
<[email protected]> wrote:
> On Miércoles, 9 de Febrero de 2011 17:11:43 gs84 escribió:
>
> > Hi everybody,
>
> > I am using Active Scaffold in list views.
> > I have to do some actions with query results after search action on
> > list.
> > So i have a method in my user controller called "export" which use the
> > result after search for exporting data into an xls file, but i don't
> > know how to get them.
>
> > Can someone help me on those 2 questions :
> > 1) how can get the AS search result after search on list?
>
> > 2) Can i use another method to export data records after search?
>
> You should send the search params to export action. If you add export link as
> an action link, you can change parameters in a before fiter (per-request
> configuration).
>
Yes i am using export link like the following:
config.action_links.add 'exportExcel', :label => '| Export to Excel
|', :page => true
I use the "exportExcel" action in which i create excel file. But
actually this fonction does not take parameter.
1) How can send the search params to export action ?
2) can you give me an example with your second proposition for the
before filter
3) If i use parameter in my exportExcel action, how can i add
collection in my routes.rb file like
map.resources :users, :active_scaffold => true, :collection
=>{ :exportExcel => :get }
Here is the export action in my controller:
def exportExcel
records = find_page().items #get active scaffold list module data
return if records.size == 0
book = Spreadsheet::Workbook.new
sheet1 = book.create_worksheet
cols = start_cols = 0
rows = start_rows = 1
cls = records[0].class
#file header
for column in User.content_columns do
sheet1[rows, cols+=1] = column.human_name
end
cols = start_cols
rows = start_rows +=1
records.each do |user|
cols = start_cols
rows = rows +=1
for column in User.content_columns do
sheet1[rows, cols+=1] = user.send(column.name)
end
end
book.write "Directory/#{cls.name.pluralize}.xls"
send_file("Directory/#{cls.name.pluralize}.xls",
:disposition => 'attachment',
:encoding => 'utf8',
:multipart => true,
:type => :xls,
:filename => cls.name.pluralize + '.xls')
end
--
You received this message because you are subscribed to the Google Groups
"ActiveScaffold : Ruby on Rails plugin" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/activescaffold?hl=en.