# DRY methodology

**URL:** <https://www.ruby-forum.com/t/dry-methodology/102296>\
**Category:** Rails\
**Created:** [February 8, 2006, 2:35am UTC](https://www.ruby-forum.com/t/dry-methodology/102296 "2006-02-08T02:35:48Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![craigrails](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/c2a13f/32.png) [@craigrails](https://www.ruby-forum.com/u/craigrails)\
**Post date:** [February 8, 2006, 2:35am UTC](https://www.ruby-forum.com/t/dry-methodology/102296/1 "2006-02-08T02:35:48Z")

</div>

because I am a grasshopper…

Now that I can sort my ‘list’…is there a logical way of not repeating  
myself to having essentially the same list view with multiple sorts?

i.e.

def list\_cl

# ordered by clients last name

```
@placement_pages, @placements = paginate(
  :placements,
  :include => [:client],
  :order_by => 'clients.last_name',
  :per_page => 14)

```

end

def list\_fac

# ordered by facility

```
@placement_pages, @placements = paginate(
  :placements,
  :include => [:facility],
  :order_by => 'facilities.name',
  :per_page => 14)

```

end

etc.

and then have links at the top of each column header to sort…

\<%= link\_to ‘Client’, :action =\> ‘list\_cl’ %\>  
\<%= link\_to ‘Facility’, :action =\> ‘list\_fac’ %\>  
…

Do I just have one ‘def list’ and then use something like a ‘case’  
statement? If so, how do I tell it from the link\_to which value?

Craig

---

<div class="post-metadata">

**Author:** ![craigrails](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/c2a13f/32.png) [@craigrails](https://www.ruby-forum.com/u/craigrails)\
**Post date:** [February 8, 2006, 5:35am UTC](https://www.ruby-forum.com/t/dry-methodology/102296/2 "2006-02-08T05:35:29Z")

</div>

Pass an extra parameter after the action.

\<%= link\_to ‘Client’, :action =\> ‘list’, :sort\_by =\> ‘client’ %\>

Estelle.

---

<div class="post-metadata">

**Author:** ![craigrails](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/c2a13f/32.png) [@craigrails](https://www.ruby-forum.com/u/craigrails)\
**Post date:** [February 8, 2006, 6:20am UTC](https://www.ruby-forum.com/t/dry-methodology/102296/3 "2006-02-08T06:20:18Z")

</div>

OK then :sort\_by becomes sort of an instance variable then? It doesn’t  
really create the ‘order\_by’ on its own right?

Craig

---

<div class="post-metadata">

**Author:** ![craigrails](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/c2a13f/32.png) [@craigrails](https://www.ruby-forum.com/u/craigrails)\
**Post date:** [February 8, 2006, 7:09am UTC](https://www.ruby-forum.com/t/dry-methodology/102296/4 "2006-02-08T07:09:35Z")

</div>

It becomes available via param[:sort\_by]

–  
– Tom M.

---

<div class="post-metadata">

**Author:** ![craigrails](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/c2a13f/32.png) [@craigrails](https://www.ruby-forum.com/u/craigrails)\
**Post date:** [February 8, 2006, 7:24am UTC](https://www.ruby-forum.com/t/dry-methodology/102296/5 "2006-02-08T07:24:42Z")

</div>

Ok - I’m tugging at it…

\<%= link\_to ‘Placements’, :controller =\> ‘placements’, :action  
=\> ‘list’, :case\_manager\_id =\> case\_manager %\>

calls placements\_controller.rb

this works…  
def list  
@placement\_pages, @placements = paginate(  
:placements,  
:conditions =\> [“placements.case\_manager\_id = ?”, ‘15’],  
:include =\> [:client],  
:order\_by =\> ‘clients.last\_name’,  
:per\_page =\> 14)  
end  
or  
:conditions =\> "placements.case\_manager\_id = “15”,  
but  
:conditions =\> "placements.case\_manager\_id =  
params[:case\_manager\_id],

gives me the syntax error near : # the :conditions line… (whether I  
use param or params - I don’t understand the difference between the two  
terms).

and I can see from \<% debug params %\>  
!map:HashWithIndifferentAccess  
action: list  
case\_manager\_id: “15”  
controller: placements  
{“action”=\>“list”, “case\_manager\_id”=\>“15”, “controller”=\>“placements”}

that case\_manager\_id with value of 15 is coming through when I simply  
comment out the conditions line altogether.

I’ve been playing with this but it’s the same form as the ‘:sort\_by’  
function so when I get one, I get both.

---

<div class="post-metadata">

**Author:** ![craigrails](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/c2a13f/32.png) [@craigrails](https://www.ruby-forum.com/u/craigrails)\
**Post date:** [February 8, 2006, 8:04am UTC](https://www.ruby-forum.com/t/dry-methodology/102296/6 "2006-02-08T08:04:35Z")

</div>

Try this:

:conditions =\> [“placements.case\_manager\_id = ?”,  
params[:case\_manager\_id] ],

---

<div class="post-metadata">

**Author:** ![craigrails](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/c2a13f/32.png) [@craigrails](https://www.ruby-forum.com/u/craigrails)\
**Post date:** [February 8, 2006, 8:19am UTC](https://www.ruby-forum.com/t/dry-methodology/102296/7 "2006-02-08T08:19:40Z")

</div>

looks like this is going to have to wait until morning…I can’t seem to  
stay connected to remote terminal now…somewhat spotty old dish  
technology at clients until they move… ;-(

I will certainly try it…you have been spot on.

Thanks

Craig

---

<div class="post-metadata">

**Author:** ![craigrails](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/c2a13f/32.png) [@craigrails](https://www.ruby-forum.com/u/craigrails)\
**Post date:** [February 8, 2006, 2:44pm UTC](https://www.ruby-forum.com/t/dry-methodology/102296/8 "2006-02-08T14:44:50Z")

</div>

\*\*\* bing \*\*\*

You are truly remarkable.
