On Aug 31, 10:37 am, Dave Castellano <[email protected]> wrote:

> I am still very new to programming and wonder if I could get some help.

Okay, but this isn't the help you're looking for.  <handwave
style="jedi" />  ;-)

>      answer_list = [
>        [incorrect_ans_1, incorrect_anno_1],
...
>        [incorrect_ans_6, incorrect_anno_6]
>        ].shuffle
...
>        formatted = {
>          :anno_1 => answer_list[0][1],
...
>          :anno_5 => answer_list[4][1],
>          :question => self.question,
>          :answer_a => answer_list[0][0],
....
>          :answer_e => answer_list[4][0]
>          }

>From a general software engineering/development standpoint, I'd
suggest you don't use things like "answer_a" to "answer_e" and so on.
Keep them in arrays, with some constant defining the size.  Then you
can just iterate over the array or range.  If you need to change the
size of the array, you can then be guaranteed that you haven't
forgotten to add or remove an entry somewhere.

>   <%= link_to_remote(
>   "B",
>   :url =>"/questions/#{@ formatted.id}/_anno_2",

And now a possible forehead-slap moment.  Might the space after the @
sign (which you have on some but not quite all of the other lines) be
causing at least part of your problem?

Iterating will also reduce the number of places where you have the
opportunity to make such mistakes.  A wise man once said, the best
code is no code at all.  See:

 http://www.codinghorror.com/blog/2007/05/the-best-code-is-no-code-at-all.html
 http://www.skrenta.com/2007/05/code_is_our_enemy.html
 http://www.capgemini.com/ctoblog/2009/02/the_best_code_is_no_code_7_way.php
 http://hackerboss.com/why-write-code-when-you-can-remove-some/

(and that's just from googling that literal phrasing.)

-Dave

-- 
Specialization is for insects. -RAH  | Have Pun, Will Babble! -me
Programming Blog: http://codosaur.us | Work: http://davearonson.com
Leadership Blog:  http://dare2xl.com | Play: http://davearonson.net
* * * * * WATCH THIS SPACE * * * * * | Ruby: http://mars.groupsite.com

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" 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/rubyonrails-talk?hl=en.

Reply via email to