# Problem with array

**URL:** <https://www.ruby-forum.com/t/problem-with-array/174150>\
**Category:** Rails\
**Created:** [August 21, 2009, 11:47am UTC](https://www.ruby-forum.com/t/problem-with-array/174150 "2009-08-21T11:47:38Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![soller](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/2acd7d/32.png) [@soller](https://www.ruby-forum.com/u/soller)\
**Post date:** [August 21, 2009, 11:47am UTC](https://www.ruby-forum.com/t/problem-with-array/174150/1 "2009-08-21T11:47:38Z")

</div>

I have two action in the same controller:

def list  
if logged\_in?  
sort = case params[‘sort’]  
when “title” then “title”  
when “a” then “a”  
when “b” then “b”  
when “c” then “c”  
when “title\_reverse” then “title DESC”  
when “a\_reverse” then “a DESC”  
when “b\_reverse” then “b DESC”  
when “c\_reverse” then “c DESC”  
end

```
if params[:query]==nil
  conditions = ["login LIKE ?", "%#{current_user.login}%"]
else
  conditions = ["login LIKE ? and title LIKE ?",

```

“%#{current\_user.login}%”,"%#{params[:query]}%"]  
end  
@total = Suma.count(:conditions =\> conditions)  
@sumas = Suma.paginate :all, :order =\> sort, :conditions =\>  
conditions, :per\_page =\> @total+1, :page =\> 1  
if request.xml\_http\_request?  
render :partial =\> “items\_list”, :layout =\> false  
end  
else  
redirect\_back\_or\_default(’/’)  
end  
end

And I have other action :

def xls

# 

```
# Creamos un nuevo archivo Excel en disco

```

# 

```
workbook = Excel.new("#{RAILS_ROOT}/public/works.xls")

```

# 

```
# AÃ±adimos hoja EMPRESAS

```

# 

```
works = workbook.add_worksheet("Works")

```

# 

```
# Fila de cabecera

```

# 

```
@cabecera = %w(title a b c)

```

# 

```
columna = 0

```

# 

```
@cabecera.each do |cab|

```

# 

```
  works.write(0,columna,cab)

```

# 

```
  columna += 1

```

# 

```
end

```

# 

```
# Una fila para cada empresa

```

# 

```
@sumas = Suma.find(:all, :conditions => ["login =

```

?",current\_user.login])  
fila = 1

# 

```
for e in @sumas

```

# 

```
  # AÃ±ado la fila con los datos en sus respectivas columnas

```

# 

```
  works.write(fila,0,e.title)

```

# 

```
  works.write(fila,1,e.a)

```

# 

```
  works.write(fila,2,e.b)

```

# 

```
  works.write(fila,3,e.c)

  # Pasamos a la siguiente empresa en una nueva fila

```

# 

```
  fila += 1

```

# 

```
end

```

I like when the user puss xls import the @sumas select in the list not  
all. Well pass list: @sumas to xls action!!  
Thank you!!
