# Deal with Controller and Action logic in RJS?

**URL:** <https://www.ruby-forum.com/t/deal-with-controller-and-action-logic-in-rjs/114680>\
**Category:** Rails\
**Created:** [September 17, 2007, 1:24pm UTC](https://www.ruby-forum.com/t/deal-with-controller-and-action-logic-in-rjs/114680 "2007-09-17T13:24:04Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![winterheat](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/7993a0/32.png) [@winterheat](https://www.ruby-forum.com/u/winterheat)\
**Post date:** [September 17, 2007, 1:24pm UTC](https://www.ruby-forum.com/t/deal-with-controller-and-action-logic-in-rjs/114680/1 "2007-09-17T13:24:04Z")

</div>

The question is, should we deal with Controller and Action logic in the  
RJS  
file? If so, is it quite “spaghetti-like”?

This is actually for the Agile Web book Shopping Cart example:

If the user clicks “Remove Item” and we do it the AJAX way,

what if we want to first show the cart’s content as

```
0 x Pragmatic Version Control $0.00

```

and then highlight it to red and back to the background color (flashing  
its  
color)

and then we will render the cart again so that the line will disappear.

Then we actually first have to decrement the quantity from 1 to 0,

then use the RJS file to draw the cart, and highlight the line  
(flashing  
its color),

and then again in the RJS file, deal with the Action logic to remove the  
CartItem from Cart

(possible by calling a method in the StoreController class)

and then redraw the cart again?

This is somewhat spaghetti like… is it that in MVC 1, the Action  
mixes  
with view logic and it is better for AJAX, but for MVC 2, the Action is  
separate from the View, so AJAX will be done by going back and forth  
from  
Action to View and back to Action again? (could be several times back  
and  
forth).

Kenneth
