jason
March 22, 2007, 2:48pm
1
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!
jason
March 22, 2007, 3:09pm
2
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?
jason
March 22, 2007, 3:48pm
3
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