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: --------- routes.rb ---------- map.resources :tickets, :collection => { :exportar=>:get, :auto_complete_for_ticket_province => :get, :auto_complete_for_ticket_city => :get, :auto_complete_for_ticket_zip => :get, :auto_complete_for_ticket_adquired_in => :get } ---------------- tickets_controller ------------------ def add_to_cartticket #Add the selected ticket to cartticket, works fine end def find_cartticket #creates a new cartticket if whe iniciates the session, works fine end def vaciar_cartticket #deletes all the tickets added to carticket in the current session, works fine end def expotar #THIS METTOD SHOULD SELECT ALL THE CURRENT TICKETS IN CARTICKET, i think works wroung @cartticket.items= Cartticket.items headers[''Contenet-type'']="aplication/vnd.ms-excel" headers[''Contenet-Disposition'']=''attachment; filename="report.xls"'' headers[''Cache-Control'']='''' end ------------------------------ add_to_cartticket.html.erb ------------------------------- h2>Tickets seleccionados </h2> <ul> <% for item in @cartticket.items %> <li><%=h item.id %></li> <% end %> </ul> <br/> <%= button_to "Vaciar" , :action => :vaciar_cartticket %> <br/> <%= link_to ''Exportar a Excel'', exportar_tickets_url %> # MUST SHOW THE SELECTED TICKETS ON .XLS COMPATIBLE ------------------------ exportar.html.erb ------------------------ <table border="1" id="doc"> <tr> <td>hola</td> <td>adios</td> <td>dew</td> </tr> <%=render :partial=> "item", :collection=>@cartticket.items %> </table> ---------------------------------- exportar.html.erb ---------------------------------- <tr> <td> <%=item.user_id%> </td> <td> <%=item.contact%> </td> <td> <%=item.phone%> </td> </tr> ---------------------------------- ++++++++++++++++++++++++++++++++++ whe i try to link to "Exportar a Excel" Firefox shows me this error: NoMethodError in Tickets#exportar 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 Extracted source (around line #9): 6: 7: <td>dew</td> 8: </tr> 9: <%=render :partial=> "item", :collection=>@cartticket.items %> 10: </table> ********************************************** Could somebody help me to find the error(s).....Thanks a lot -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On Nov 19, 11:24 pm, Jose vicente Ribera pellicer <rails-mailing- l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> 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.itemsYou don''t seem to be setting @cartticket anywhere. Fred> > Extracted source (around line #9): > > 6: > 7: <td>dew</td> > 8: </tr> > 9: <%=render :partial=> "item", :collection=>@cartticket.items %> > 10: </table> > > ********************************************** > > Could somebody help me to find the error(s).....Thanks a lot > -- > Posted viahttp://www.ruby-forum.com/.--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Frederick Cheung wrote:> On Nov 19, 11:24�pm, Jose vicente Ribera pellicer <rails-mailing- > l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> 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. > > FredI 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. -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On 20 Nov 2008, at 15:37, Jose vicente Ribera pellicer wrote:> > Frederick Cheung wrote: >> On Nov 19, 11:24�pm, Jose vicente Ribera pellicer <rails-mailing- >> l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> 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> 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. > > > -- > Posted via http://www.ruby-forum.com/. > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Frederick Cheung wrote:> On 20 Nov 2008, at 15:37, Jose vicente Ribera pellicer 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. > > FredSo I will find @cartticket before select the items really? -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On 20 Nov 2008, at 18:10, Jose vicente Ribera pellicer wrote:> > Frederick Cheung wrote: >> On 20 Nov 2008, at 15:37, Jose vicente Ribera pellicer 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> > -- > Posted via http://www.ruby-forum.com/. > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
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 -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On 20 Nov 2008, at 18:59, Jose vicente Ribera pellicer wrote:> > 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 thisthat looks fine to me (ps send_data/send_file might help you reduce typos in those headers) Fred> > -- > Posted via http://www.ruby-forum.com/. > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
thanks a lot!! -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---