# SortHelper Problem with column name

**URL:** <https://www.ruby-forum.com/t/sorthelper-problem-with-column-name/87109>\
**Category:** Rails\
**Created:** [February 28, 2007, 9:54am UTC](https://www.ruby-forum.com/t/sorthelper-problem-with-column-name/87109 "2007-02-28T09:54:45Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![claudio](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/7cd45c/32.png) [@claudio](https://www.ruby-forum.com/u/claudio)\
**Post date:** [February 28, 2007, 9:54am UTC](https://www.ruby-forum.com/t/sorthelper-problem-with-column-name/87109/1 "2007-02-28T09:54:45Z")

</div>

In my newscontroller I have two lists category\_list and news\_list

def category\_list  
sort\_init ‘name’  
sort\_update

end

---

<div class="post-metadata">

**Author:** ![claudio](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/7cd45c/32.png) [@claudio](https://www.ruby-forum.com/u/claudio)\
**Post date:** [February 28, 2007, 9:57am UTC](https://www.ruby-forum.com/t/sorthelper-problem-with-column-name/87109/2 "2007-02-28T09:57:17Z")

</div>

sorry i pressed enter wrongly

In my newscontroller I have two lists category\_list and news\_list  
def category\_list  
sort\_init ‘name’  
sort\_update  
… :order =\> sort\_clause  
end

def news\_list  
sort\_init ‘title’  
sort\_update  
… :order =\> sort\_clause  
end

The problem is that when i try to see the news\_list the sorthelper sort  
by name that doesn’t exist in the news table or vice versa

any suggestions for this?

---

<div class="post-metadata">

**Author:** ![claudio](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/7cd45c/32.png) [@claudio](https://www.ruby-forum.com/u/claudio)\
**Post date:** [February 28, 2007, 10:35am UTC](https://www.ruby-forum.com/t/sorthelper-problem-with-column-name/87109/3 "2007-02-28T10:35:27Z")

</div>

claudio wrote:

> sorry i pressed enter wrongly
> 
> In my newscontroller I have two lists category\_list and news\_list  
> def category\_list  
> sort\_init ‘name’  
> sort\_update  
> … :order =\> sort\_clause  
> end
> 
> def news\_list  
> sort\_init ‘title’  
> sort\_update  
> … :order =\> sort\_clause  
> end
> 
> The problem is that when i try to see the news\_list the sorthelper sort  
> by name that doesn’t exist in the news table or vice versa
> 
> any suggestions for this?

I figured out by myself, in the SortHelper.rb in sort\_update method on  
line 92  
youo have to modify  
elseif session[@sort\_name]  
in  
elseif session[@sort\_name][:key] == @sort\_default[:key]

because you change one list to another one the sorthelper take the last  
key  
in the session without update.

---

<div class="post-metadata">

**Author:** ![claudio](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/7cd45c/32.png) [@claudio](https://www.ruby-forum.com/u/claudio)\
**Post date:** [February 28, 2007, 1:04pm UTC](https://www.ruby-forum.com/t/sorthelper-problem-with-column-name/87109/4 "2007-02-28T13:04:19Z")

</div>

> I figured out by myself, in the SortHelper.rb in sort\_update method on  
> line 92  
> youo have to modify  
> elseif session[@sort\_name]  
> in  
> elseif session[@sort\_name][:key] == @sort\_default[:key]
> 
> because you change one list to another one the sorthelper take the last  
> key  
> in the session without update.

i figured out one more time:  
this up is wrong the correct way is:

def sort\_update()  
if params[:sort\_key]  
sort = {:key =\> params[:sort\_key], :order =\> params[:sort\_order]}  
elsif session[@sort\_name]  
if session[@sort\_name][:key] == @sort\_default[:key]  
sort = session[@sort\_name]  
else  
sort = @sort\_default  
end  
else  
sort = @sort\_default  
end  
session[@sort\_name] = sort  
end
