# Inconsistent Invalid Argument Error

**URL:** <https://www.ruby-forum.com/t/inconsistent-invalid-argument-error/89755>\
**Category:** Rails\
**Created:** [March 22, 2007, 2:48pm UTC](https://www.ruby-forum.com/t/inconsistent-invalid-argument-error/89755 "2007-03-22T14:48:19Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![jason](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/dc4da7/32.png) [@jason](https://www.ruby-forum.com/u/jason)\
**Post date:** [March 22, 2007, 2:48pm UTC](https://www.ruby-forum.com/t/inconsistent-invalid-argument-error/89755/1 "2007-03-22T14:48:19Z")

</div>

I have a view with a table that contains sortable links as headings.  
Here is the code used to create these sortable links in the  
application\_helper:

module ApplicationHelper  
def sort\_link\_helper(text, param)  
key = param  
key += “\_reverse” if @params[:sort] == param

```
link_to(text, :controller => 'sales_orders', :action => 'list',

```

:sort =\> key )  
end  
end

Here is the code in my controller where I call the sort\_link\_helper  
function:

 \<%= sort\_link\_helper 'Number', 'id' %\> \<%= sort\_link\_helper 'Sold To', 'sold\_to' %\> \<%= sort\_link\_helper 'Ship To', 'ship\_to' %\> \<%= sort\_link\_helper 'Rep', 'rep' %\> \<%= sort\_link\_helper 'Description', 'description' %\> \<%= sort\_link\_helper 'Amount', 'amount' %\> \<%= sort\_link\_helper 'Ship Date', 'ship\_date' %\> Current Status 

The problem is that sometimes, when I click one of these links to sort  
the table by that field, I get the following error:

Showing app/views/sales\_orders/list.rhtml where line #29 raised:

Invalid argument

Extracted source (around line #29):

26:

\<%= sort\_link\_helper ‘Rep’, ‘rep’ %\>  
27: \<%= sort\_link\_helper ‘Description’, ‘description’  
%\>  
28: \<%= sort\_link\_helper ‘Amount’, ‘amount’ %\>  
29: \<%= sort\_link\_helper ‘Ship Date’, ‘ship\_date’ %\>  
30: Current Status  
31:   
32:

It is maddeningly inconsistent. Sometimes, I can just do a refresh and  
it’ll work fine. Sometimes I have to refresh several times before I can  
get it to work. Also, the line number causing the error will be  
different sometimes, but it’s always one of the lines with the  
sort\_link\_helper in it.

Any ideas on how I can get this fixed?

Thanks!

---

<div class="post-metadata">

**Author:** ![jason](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/dc4da7/32.png) [@jason](https://www.ruby-forum.com/u/jason)\
**Post date:** [March 22, 2007, 3:09pm UTC](https://www.ruby-forum.com/t/inconsistent-invalid-argument-error/89755/2 "2007-03-22T15:09:44Z")

</div>

I have narrowed the problem down a bit:

def sort\_link\_helper(text, param)  
key = param

```
#the following line is the culprit. I'm not sure what I'm doing 

```

wrong here.  
key += “\_reverse” if @params[:sort] == param

```
link_to(text, :controller => 'sales_orders', :action => 'list', 

```

:sort =\> key )  
end

What is wrong with the line above that adds ‘\_reverse’ to the key?

---

<div class="post-metadata">

**Author:** ![jason](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/dc4da7/32.png) [@jason](https://www.ruby-forum.com/u/jason)\
**Post date:** [March 22, 2007, 3:48pm UTC](https://www.ruby-forum.com/t/inconsistent-invalid-argument-error/89755/3 "2007-03-22T15:48:38Z")

</div>

Jason wrote:

> I have narrowed the problem down a bit:
> 
> def sort\_link\_helper(text, param)  
> key = param
> 
> ```
> #the following line is the culprit. I'm not sure what I'm doing 
> 
> ```
> 
> wrong here.  
> key += “\_reverse” if @params[:sort] == param
> 
> ```
> link_to(text, :controller => 'sales_orders', :action => 'list', 
> 
> ```
> 
> :sort =\> key )  
> end
> 
> What is wrong with the line above that adds ‘\_reverse’ to the key?

I figured this out. Should be without the @:

def sort\_link\_helper(text, param)  
key = param  
key += “\_reverse” if params[:sort] == param

```
link_to(text, :controller => 'sales_orders', :action => 'list',

```

:sort =\> key )  
end
