# General question on design

**URL:** <https://www.ruby-forum.com/t/general-question-on-design/149382>\
**Category:** Rails\
**Created:** [September 24, 2008, 10:56am UTC](https://www.ruby-forum.com/t/general-question-on-design/149382 "2008-09-24T10:56:41Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![bskaggs](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/3ab097/32.png) [@bskaggs](https://www.ruby-forum.com/u/bskaggs)\
**Post date:** [September 24, 2008, 10:56am UTC](https://www.ruby-forum.com/t/general-question-on-design/149382/1 "2008-09-24T10:56:41Z")

</div>

Hi

I am thinking about the design of my application, I understand its  
crucial to limit the amount of core code from the view.

I seemed to have designed my app in a way found in an online tutorial,  
and am now encountering a few design issues.

For example,

my controllers seem to run along these lines:

# testruns

def run  
@testcase = Testcase.find(:all)  
@testsuite = Testsuite.find(params[:id])  
@version = Version.find(params[:id1])  
@testruns = Testrun.find(:all)  
@testrun = Testrun.find(:all).last.id  
end

and the view:

\<% @testsuite.testcases.each do |tc| %\>

**\<%= link\_to tc.number, {:controller =\> 'testrun', :action =\> 'runtest', :id =\> tc.id, :id1 =\> @testrun, :id2 =\> @testsuite.id, :id3 =\> @version } -%\>** 

```
<td align="left"><b><%= tc.description -%></b></td>
<td align="left"><b><%= debug Result.find_by_resulttype(:all,

```

:conditions =\> {:id =\> [1]}) %\>

**\<%= @outcome.outcome\_date %\>** \<% end %\>

The problem is, now I have to write some more detailed queries, like  
this for example:  
@passed = Outcome.count(:all, :conditions =\> ‘outcomes.outcome\_date =  
(select max(o2.outcome\_date) from outcomes o2 where o2.testrun\_id =  
outcomes.testrun\_id and o2.testcase\_id = outcomes.testcase\_id and  
outcomes.testrun\_id = @testrun and outcomes.testcase\_id = tc.id)’)

In the above the @testrun is set in the controller, and tc.id is  
iterated through in the each do loop.

But the @passed query, is coded into the view, this obviously should be  
a speerated concern from the view and in the controller, but I cant  
figure out how to transfer the loop, because I need the tc.id into the  
controller, and then pass the values across to the view as it iterates.

Can anyone help?

Can you give me a few pointers, to be honest I am a newbie, and have  
hacked out some code, Im going to start the agile programming ruby book  
this weekend, but most of the functional lines of that book seem to be  
for useless design, things I dont really have interest in developing,  
but I suppose the principles are still worth learning.

Are there any other areas of study you would recommend?

Thanks…

---

<div class="post-metadata">

**Author:** ![bskaggs](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/3ab097/32.png) [@bskaggs](https://www.ruby-forum.com/u/bskaggs)\
**Post date:** [September 24, 2008, 11:34am UTC](https://www.ruby-forum.com/t/general-question-on-design/149382/2 "2008-09-24T11:34:13Z")

</div>

On 24 Sep 2008, at 09:56, Brad S. wrote:

> my controllers seem to run along these lines:
> 
> # testruns
> 
> def run  
> @testcase = Testcase.find(:all)  
> @testsuite = Testsuite.find(params[:id])  
> @version = Version.find(params[:id1])  
> @testruns = Testrun.find(:all)  
> @testrun = Testrun.find(:all).last.id  
> end

not relevant to this, but it’s a bit wasteful to fetch all test runs  
just to get the id of the last one. I’d either use find :first, or in  
this case since you’ve already loaded them all anyway (although you  
don’t seem to be using them) eg @testrun = @testruns.last.id

> **\<%= debug Result.find\_by\_resulttype(:all, outcomes.testrun\_id and o2.testcase\_id = outcomes.testcase\_id and outcomes.testrun\_id = @testrun and outcomes.testcase\_id = tc.id)')**
> 
> something like that belongs in a model (perhaps an instance method of  
> test run or something). pass any extra parameters in as parameters to  
> that method
> 
> Fred
