hi all,
can we pass an object to an action thru link_to? e.g. <%= link_to
‘action’, :action=>‘action’, :object=>@obj %>.
I’m showing a report to the user and on the same page, i’ve a link
that generates a csv for that report. and i’ve a separate function to
generate csv for which i need to send this report obj to csv function.
both, report and csv functions, are in the same controller. is it
possible? or is thr any othr way?
-Dhaval
Yes you can, but not sure what the @obj is that you are referring to.
If it is a model, then the id will suffice for the object to be looked
up again at the server. If it is other data then you will need to
send a reference to the report so it can be regenerated at the server,
or you can send the individual fields of an object. Like posting a
form, they will appear in params
Tonypm
tonypm wrote:
Yes you can, but not sure what the @obj is that you are referring to.
If it is a model, then the id will suffice for the object to be looked
up again at the server. If it is other data then you will need to
send a reference to the report so it can be regenerated at the server,
or you can send the individual fields of an object. Like posting a
form, they will appear in params
Tonypm
thanks for reply Tonypm. basically, @report holds the complete report
data. like name,addr etc etc came from an xml response. on clicking the
csv link, i needed to pass this same @report object to csv function so
that i could access the data thr and could generate the csv. still
working on that though :). right now wt i did is regenerated the report
in the csv function and generated csv for the same. its working but
giving following usual error for few fields.
“NoMethodError in Order reportsController#xls
You have a nil object when you didn’t expect it!
The error occurred while evaluating nil.text”
and yes, thanks for the info again
-Dhaval
still couldn’t figured this out. can anybody tell me the correct way to
do this, please? i need to pass/access an object from one method to
another in the same controller.
Report controller:-
def report_type
@report = @report holds xml response
code…
end
def get_csv
need @report from above method to generate csv
code…
end
report_type.rhtml contains a link as -
<%= link_to ‘Export to CSV’,:action=>‘get_csv’,@report %>
i tried sending @report, :object=>@report, :id=>@report but nothing
worked.
thanks in adv
-DP
On 11 Aug 2008, at 12:10, Dhaval P. wrote:
end
i tried sending @report, :object=>@report, :id=>@report but nothing
worked.
If report is only a small amount of data (i suspect not) then you
could break it into query params (ie :title => @report.title etc…)
If not then you’ll need to persist the report object in some fashion
(eg the database) so that you can retrieve it when the get_csv request
comes in.
Fred
thanks for the reply Fred.
If report is only a small amount of data (i suspect not) then you
could break it into query params (ie :title => @report.title etc…)
yes, you are right, report data is not a small one and as i
said,@report holds xml response(i post a request to a server and receive
a response), so will i be able to generate csv values in the loop, with
:title=>@report.title etc…? i suppose it will pass only one title
value, correct me if i’m wrong.
If not then you’ll need to persist the report object in some fashion
(eg the database) so that you can retrieve it when the get_csv request
comes in.
do you have any idea about how it can be done? can we use session
variable for this? i.e. in report_type method, session[:rep]= @report or
something like that?
-DP