Hi. I have been using Haml for a few days. I have converted one of
my smaller apps over to it and I love it! However, I am having one
weird problem that is making me pull my hair out. It is going to be
tough to explain, but here goes:
I have a table where I am trying to set one of the column headings to
be class="sortup" if the table is currently sorted by that column.
This works fine when I first create the view. However, on subsequent
page reloads, after I have clicked another column heading, it never
changes the class for the tags in question.
Here is my table haml code:
<pre>
%table
%thead
%tr
%td{ :class => sort_td_class_helper('dept_no') }=
sort_link_helper('Dept. No.', 'dept_no')
%td{ :class => sort_td_class_helper('name') }=
sort_link_helper('Name', 'name')
%td{ :class => sort_td_class_helper('include_detail') }=
sort_link_helper('Include Detail?', 'include_detail')
%td Manager
%td.action Actions
%tbody
= render :partial => 'department', :collection => @departments
</pre>
Here are the two helpers mentioned above:
<pre>
def sort_td_class_helper(table_field_name)
if params['sort'] == table_field_name
'sortup'
elsif params['sort'] == table_field_name + "_reverse"
'sortdown'
else
''
end
end
def sort_link_helper(text, param)
key = param
key += "_reverse" if params[:sort] == param
options = {
:url => {:action => 'list', :params => params.merge({:sort =>
key,
:page => nil})},
:update => 'tablediv',
:before => "Element.show('spinner')",
:success => "Element.hide('spinner')"
}
html_options = {
:title => "Sort by this field",
:href => url_for(:action => 'list', :params => params.merge(
{:sort => key, :page => nil}))
}
link_to_remote(text, options, html_options)
end
</pre>
And here is the controller code:
<pre>
def list
params['sort'] = "dept_no" if params['sort'].blank?
sort = case params['sort']
when "dept_no" then "dept_no"
when "name" then "name"
when "include_detail" then "include_detail"
when "dept_no_reverse" then "dept_no DESC"
when "name_reverse" then "name DESC"
when "include_detail_reverse" then "include_detail DESC"
end
if params[:query].blank?
conditions = nil
else
conditions_str = case params['filter_field']
when 'Dept. No.' then "dept_no LIKE ?"
when 'Dept. Name' then "name LIKE ?"
end
conditions = [conditions_str, params[:query]+'%']
end
@department_pages, @departments = paginate :departments, :order =>
sort,
:conditions => conditions, :per_page => 15
if request.xml_http_request?
render :partial => "table", :layout => false
end
@page_title = 'Listing departments'
end
</pre>
I've verified that the sort_td_class helper is passing back the
correct value each time it is called, but it does not appear that the
html code is regenerated each time I click on a header, even though I
know the controller action is running because the table gets resorted.
Is there someting bone-headed that I am missing?
Thanks.
Jamey Cribbs
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Haml" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/haml?hl=en
-~----------~----~----~----~------~----~------~--~---