Simply scenario -- I have two buttons both of which call the same controller/action. The controller action sets a random number, @random_number.
If I click button 1, I want the view to change (via JS) by displaying the @random_number in RED. If I click button 2, I want the view to change (via JS) by displaying the @random_number in GREEN.
What is the DRY-est way to do this? My understanding of rails's controller/view layers is that each controller/action is associated with a corresponding view. But in this case, I want to use the same business logic (generate a random number) for both button clicks but the resulting view depends on which button is clicked.
One option is to pass the button id to the controller/action and then use the button id in the controller/action's associated RJS file to execute the appropriate javascript. But my gut tells me that this is not the best way. Is there a better way?
A quick code sample would be much appreciated.
Thanks.