Hello
New to ruby
i have to current code :
xml.Worksheet 'ss:Name' => 'Sheet1' do
xml.Table do
# Header
xml.Row do
for column in @model.content_columns do
xml.Cell do
xml.Data column.human_name, 'ss:Type' => 'String'
end
end
end
# Rows
for record in @export
xml.Row do
for column in @model.content_columns do
xml.Cell do
xml.Data record.send(column.name), 'ss:Type' =>
'String'
end
end
end
end
end
end
it does extract data to an excel worksheet.
Where @model is the model name ( ex: User)
and @export is record set( ex: @export=User.find(:all) )
i want to eliminate some columns of being extracted. Let's say i want
to export just the first_name and not the whole table
Any suggestion will be appreciated
Thank you
Fred
I have a feeling you've taken this code from somewhere on the web
without first trying to understand it. Am I right? If so: DON'T DO
THAT. Understand the code before you steal the code. But see below
for my hint.
xml.Worksheet 'ss:Name' => 'Sheet1' do
xml\.Table do
\# Header
xml\.Row do
for column in @model\.content\_columns do
xml\.Cell do
xml\.Data column\.human\_name, 'ss:Type' => 'String'
end
end
end
\# Rows
for record in @export
xml\.Row do
for column in @model\.content\_columns do
xml\.Cell do
xml\.Data record\.send\(column\.name\), 'ss:Type' =>
'String'
end
end
end
end
end
end
it does extract data to an excel worksheet.
Where @model is the model name ( ex: User)
and @export is record set( ex: @export=User.find(:all) )
i want to eliminate some columns of being extracted. Let's say i want
to export just the first_name and not the whole table
Any suggestion will be appreciated
Your problem is you don't understand what @model.content_columns is
doing: it's getting all the columns for that model. If you want only
specific columns, then just get the data for the columns you want.
Hey though
i didnt steal it from anywhere. it comes with a pluging as a sample
code. I'm looking for help here and not for philosophers.
I use a find_by_sql instead of find(:all), so am just extracting 1
column (first_name).
i got the following error : missing attribute: middle_name.
maybe because the headers and columns numbers should map?
Anyone have an idea about what's going on?
Thank you
I use a find_by_sql instead of find(:all), so am just extracting 1
column (first_name).
i got the following error : missing attribute: middle_name.
maybe because the headers and columns numbers should map?
Doing a find_by_sql whilst only selecting some columns from the table
won’t make content_columns play nicely because content_columns expects
the returned object to have ALL the columns.
I’m looking for help here and not for philosophers.
May I point out to you that the help is free. Be prepared to get some responses you won’t like.