respond_to do |format|
format.html # show.html.erb
format.xls { render :to_excel_2003 => @data }
end
and to_excel_2003 only contains a debugger call, which is never reached.
Two more questions:
How to overcome the "Template is missing" - an .erb-file doesn't make
sense here.
How to build the link_to to generate a link to the .xls-file?
This is just as wrong, you just need to serve up data using what's
available in Rails. Anyway, send_data is the thing you want.
There is an example in responde_to:
def index
@people = Person.find(:all)
respond_to do |format|
format.html
format.xml { render :xml => @people.to_xml }
end
end
For me, to_xml looks like method of the class of @people. Right?
My data is in @data, which needs to be rendered into the excel xml
format using a template consisting of xml fragments and variables, that
will be expanded using the content of @data.
send_data will be the very last step.
The point is, that the excel file doesn't exist and should be created on
the fly.
This is just as wrong, you just need to serve up data using what’s
available in Rails. Anyway, send_data is the thing you want.
Peter De Berdt wrote:
There is an example in responde_to:
def index
@people = Person.find(:all)
respond_to do |format|
format.html
format.xml { render :xml => @people.to_xml }
end
end
For me, to_xml looks like method of the class of @people. Right?
Well, it’s actually a method from Enumerable or Array which renders it to an XML format according to Rails specifications. That doesn’t mean Excel will be able to read it (and it won’t, I can tell you right now).
My data is in @data, which needs to be rendered into the excel xml
format using a template consisting of xml fragments and variables, that
will be expanded using the content of @data.
send_data will be the very last step.
The point is, that the excel file doesn’t exist and should be created on
the fly.
Uhu, and your point is?
You have three options:
Make a template in excel with some variables (I would recommend using something like liquid instead of erb) and run them through the template parser of your choice
Generate an excel file using one of the gems you find when googling “ruby excel”, your mileage may vary on those
Generate an excel file using your own code based on the public spec available from Mickeysoft
format.html
format.xml { render :xml => @people.to_xml }
end
end
For me, to_xml looks like method of the class of @people. Right?
Well, it's actually a method from Enumerable or Array which renders it
to an XML format according to Rails specifications. That doesn't mean
Excel will be able to read it (and it won't, I can tell you right now).
It's really a member function of
class data < ActiveRecord::Base
def to_excel_2003
debugger
end
end
and gets called from format.xls { render :xls => @data.to_excel_2003 }
My problem now is to find a trick to redirect back to show after
downloading the file.
As a result, the client should ge a download dialog to store the file.
You have three options:
- Make a template in excel with some variables (I would recommend
using something like liquid instead of erb) and run them through the
template parser of your choice
- Generate an excel file using one of the gems you find when googling
"ruby excel", your mileage may vary on those
This is too much efford. I developed the xml-solution for javascript and
it works very well.
To design and format such a sheet, simply use excel or OpenOffice and
export it as excel 2003 format, then take a xml editor like XML Copy
Editor, pretty print it and extract varable blocks to xml fragments and
set variables instead.
This is something like a template and my to_excel_2003 should act as a
template parser. Any idea, how to do this?
- Generate an excel file using your own code based on the public spec
available from Mickeysoft
Instead of render :xls, use send_data with the correct options to serve the file with disposition attachment (see the docs), this will bring up the dialog box right away and you never have to redirect to show, since a file download doesn’t do a page refresh.
You’ll need to implement the to_excel_2003 method to return a string at the end that will constitute the contents of the file. It’s up to you to figure out which method of actually generating the string fits your project best and implement it.
i have installed
ruby 1.8.6 window version,
rails 2.0.2
everything runs fine except SCAFFOLD
when i run
ruby script/generate scaffold modelname controllername actions
e,g. C:depot>ruby script/generate scaffold Album albums
it gives following error
"WRONG NUMBER OF ARGUMENTS (1 FOR 2)"
i tried with many dummyprojects and tutorial,
BUT if i run
ruby script/generate scaffold modelname
e.g ruby script/generate scaffold Album
IT'S RUN FINE
SEE THE FOLLOWING
C:\InstantRails-2.0-win_2\rails_apps\music_library_development>ruby
script/generate scaffold Album albums
exists app/models/
exists app/controllers/
exists app/helpers/
create app/views/products
exists app/views/layouts/
exists test/functional/
exists test/unit/
create app/views/products/index.html.erb
wrong number of arguments (1 for 2)
BUT RESULTS ARE A BIT DIFFERENT ,
i am looking for Modelname "album", Controllername " albums "
and Actions "show.rhtml, new.rhml, edit.rhtml,_form.rhtml"
BUT RESULTS ARE
Modelname " album" , Controllername " albums",and Actions
"show.html.erb,new.html.erb,edit.html.erb,index.html.erb"