11175
(-- --)
November 19, 2008, 11:24pm
1
First and foremost sorry if my english is not the best.
In my application I have a view with tickets and i can select it one to
one with a button.
The selected tickets go to another view that shows me the tickets i have
choosen. I want to export this selected tickets to excell.
My code is the next:
Showing tickets/exportar.html.erb where line #9 raised:
You have a nil object when you didn't expect it!
The error occurred while evaluating nil.items
You don't seem to be setting @cartticket anywhere.
Fred
11175
(-- --)
November 20, 2008, 3:37pm
3
Frederick Cheung wrote:
Showing tickets/exportar.html.erb where line #9 raised:
You have a nil object when you didn't expect it!
The error occurred while evaluating nil.items
You don't seem to be setting @cartticket anywhere.
Fred
I dont`t think so, because in ticket controller this code works fine:
def add_to_cartticket
@cartticket = find_cartticket
ticket = Ticket.find(params[:id])
@cartticket.add_ticket (ticket)
end
def find_cartticket
unless session[:cartticket] # if there's no cart in the session
session[:cartticket] = Cartticket.new # add a new one
end
session[:cartticket] # return existing or new cart
end
thanks for the answer. Now i'm not implementing this code, only appears
in the add_to_cartticket view one table with the fields i want to show.
Next step if I can`t sole tehe excel problem will be print it directly.
Frederick Cheung wrote:
Showing tickets/exportar.html.erb where line #9 raised:
You have a nil object when you didn't expect it!
The error occurred while evaluating nil.items
You don't seem to be setting @cartticket anywhere.
Fred
I dont`t think so, because in ticket controller this code works fine:
def add_to_cartticket
@cartticket = find_cartticket
ticket = Ticket.find(params[:id])
@cartticket.add_ticket (ticket)
end
That's irrelevant. when your expotar action is called you get a new
instance of the Controller - instance variables don't persist across
requests.
Fred
Frederick Cheung wrote:
end
That's irrelevant. when your expotar action is called you get a new
instance of the Controller - instance variables don't persist across
requests.
Fred
So I will find @cartticket before select the items really?
Sorry, I can't parse that sentence.
Fred
11175
(-- --)
November 20, 2008, 6:59pm
6
Sorry. I think this is the solution that you're trying to show me:
def expotar #THIS METTOD SHOULD SELECT ALL THE CURRENT TICKETS IN
CARTICKET, i think works wroung
@cartticket = find_cartticket
@tickets=@cartticket.items
headers['Contenet-type']="aplication/vnd.ms-excel"
headers['Contenet-Disposition']='attachment; filename="report.xls"'
headers['Cache-Control']=''
end
@tickets has the tickets that y need.
I think you were trying to say this
Sorry. I think this is the solution that you're trying to show me:
def expotar #THIS METTOD SHOULD SELECT ALL THE CURRENT TICKETS IN
CARTICKET, i think works wroung
@cartticket = find_cartticket
@tickets=@cartticket.items
headers['Contenet-type']="aplication/vnd.ms-excel"
headers['Contenet-Disposition']='attachment; filename="report.xls"'
headers['Cache-Control']=''
end
@tickets has the tickets that y need.
I think you were trying to say this
that looks fine to me (ps send_data/send_file might help you reduce
typos in those headers)
Fred