General question on design

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| %>
  <tr>
    <td align="left"><b><%= link_to tc.number, {:controller =>
'testrun', :action => 'runtest', :id => tc.id, :id1 => @testrun, :id2 =>
@testsuite.id, :id3 => @version } -%> </b></td>

    <td align="left"><b><%= tc.description -%></b></td>
    <td align="left"><b><%= debug Result.find_by_resulttype(:all,
:conditions => {:id => [1]}) %></b></td>
    <td align="left"><b><%= @outcome.outcome_date %></b></td>
  </tr>
<% 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...

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

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

and the view:

<% @testsuite.testcases.each do |tc| %>
<tr>
   <td align="left"><b><%= link_to tc.number, {:controller =>
'testrun', :action => 'runtest', :id => tc.id, :id1 => @testrun, :id2 =>
@testsuite.id, :id3 => @version } -%> </b></td>

   <td align="left"><b><%= tc.description -%></b></td>
   <td align="left"><b><%= debug Result.find_by_resulttype(:all,
:conditions => {:id => [1]}) %></b></td>
   <td align="left"><b><%= @outcome.outcome_date %></b></td>
</tr>
<% 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)')

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