# Help with partial

**URL:** <https://www.ruby-forum.com/t/help-with-partial/153673>\
**Category:** Rails\
**Created:** [November 20, 2008, 12:24am UTC](https://www.ruby-forum.com/t/help-with-partial/153673 "2008-11-20T00:24:12Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![chimorito](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/54ee81/32.png) [@chimorito](https://www.ruby-forum.com/u/chimorito)\
**Post date:** [November 20, 2008, 12:24am UTC](https://www.ruby-forum.com/t/help-with-partial/153673/1 "2008-11-20T00:24:12Z")

</div>

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

\<% for item in @cartticket.items %\>- \<%=h item.id %\>
\<% end %\>
  
\<%= button\_to "Vaciar" , :action =\> :vaciar\_cartticket %\>  

\<%= link\_to ‘Exportar a Excel’, exportar\_tickets\_url %\> # MUST SHOW THE  
SELECTED TICKETS ON .XLS COMPATIBLE

* * *

## exportar.html.erb

```
<td>adios</td>

<td>dew</td>

```

 \<%=render :partial=\> "item", :collection=\>@cartticket.items %\> 

| hola |

---------------------------------- exportar.html.erb ---------------------------------- \<%=item.user\_id%\> \<%=item.contact%\> \<%=item.phone%\> 
## 

++++++++++++++++++++++++++++++++++

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:

dew  
8:   
9: \<%=render :partial=\> “item”, :collection=\>@cartticket.items %\>  
10: 
* * *

Could somebody help me to find the error(s)…Thanks a lot

---

<div class="post-metadata">

**Author:** ![chimorito](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/54ee81/32.png) [@chimorito](https://www.ruby-forum.com/u/chimorito)\
**Post date:** [November 20, 2008, 12:43am UTC](https://www.ruby-forum.com/t/help-with-partial/153673/2 "2008-11-20T00:43:50Z")

</div>

On Nov 19, 11:24 pm, Jose vicente Ribera pellicer \<rails-mailing-  
removed\_email\_address@domain.invalid\> 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

---

<div class="post-metadata">

**Author:** ![chimorito](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/54ee81/32.png) [@chimorito](https://www.ruby-forum.com/u/chimorito)\
**Post date:** [November 20, 2008, 4:37pm UTC](https://www.ruby-forum.com/t/help-with-partial/153673/3 "2008-11-20T16:37:35Z")

</div>

Frederick C. wrote:

> On Nov 19, 11:24ï¿½pm, Jose vicente Ribera pellicer \<rails-mailing-  
> removed\_email\_address@domain.invalid\> 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.

---

<div class="post-metadata">

**Author:** ![chimorito](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/54ee81/32.png) [@chimorito](https://www.ruby-forum.com/u/chimorito)\
**Post date:** [November 20, 2008, 7:10pm UTC](https://www.ruby-forum.com/t/help-with-partial/153673/4 "2008-11-20T19:10:31Z")

</div>

Frederick C. 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?

---

<div class="post-metadata">

**Author:** ![chimorito](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/54ee81/32.png) [@chimorito](https://www.ruby-forum.com/u/chimorito)\
**Post date:** [November 20, 2008, 5:32pm UTC](https://www.ruby-forum.com/t/help-with-partial/153673/5 "2008-11-20T17:32:13Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![chimorito](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/54ee81/32.png) [@chimorito](https://www.ruby-forum.com/u/chimorito)\
**Post date:** [November 20, 2008, 7:22pm UTC](https://www.ruby-forum.com/t/help-with-partial/153673/6 "2008-11-20T19:22:35Z")

</div>

On 20 Nov 2008, at 18:10, Jose vicente Ribera pellicer wrote:

> > requests.
> > 
> > Fred
> 
> So I will find @cartticket before select the items really?  
> Sorry, I can’t parse that sentence.

Fred

---

<div class="post-metadata">

**Author:** ![chimorito](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/54ee81/32.png) [@chimorito](https://www.ruby-forum.com/u/chimorito)\
**Post date:** [November 20, 2008, 7:59pm UTC](https://www.ruby-forum.com/t/help-with-partial/153673/7 "2008-11-20T19:59:10Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![chimorito](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/54ee81/32.png) [@chimorito](https://www.ruby-forum.com/u/chimorito)\
**Post date:** [November 21, 2008, 12:05pm UTC](https://www.ruby-forum.com/t/help-with-partial/153673/8 "2008-11-21T12:05:20Z")

</div>

On 20 Nov 2008, at 18:59, Jose vicente Ribera pellicer wrote:

> 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

---

<div class="post-metadata">

**Author:** ![chimorito](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/54ee81/32.png) [@chimorito](https://www.ruby-forum.com/u/chimorito)\
**Post date:** [November 21, 2008, 5:35pm UTC](https://www.ruby-forum.com/t/help-with-partial/153673/9 "2008-11-21T17:35:20Z")

</div>

thanks a lot!!
