# Re: ajax and partials

**URL:** <https://www.ruby-forum.com/t/re-ajax-and-partials/194239>\
**Category:** Rails\
**Created:** [September 1, 2010, 2:56pm UTC](https://www.ruby-forum.com/t/re-ajax-and-partials/194239 "2010-09-01T14:56:21Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![daveamos](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/a698b9/32.png) [@daveamos](https://www.ruby-forum.com/u/daveamos)\
**Post date:** [September 1, 2010, 2:56pm UTC](https://www.ruby-forum.com/t/re-ajax-and-partials/194239/1 "2010-09-01T14:56:21Z")

</div>

On Aug 31, 10:37 am, Dave C. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) 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. 😉

> ```
> 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.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.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://www.capgemini.com/ctoblog/2009/02/the_best_code_is_no_code_7_way.php)  
[Why Write Code When You Can Remove Some? | Hacker Boss](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](http://codosaur.us) | Work: [http://davearonson.com](http://davearonson.com)  
Leadership Blog: [http://dare2xl.com](http://dare2xl.com) | Play: [http://davearonson.net](http://davearonson.net)

- 
  - 
    - 
      - 
        - WATCH THIS SPACE \* \* \* \* \* | Ruby: [http://mars.groupsite.com](http://mars.groupsite.com)
