I have developed a normal browser-based Rails game application. I'm now adding CloudMailin to the mix, effectively exposing an alternative interface via email.
Consider, as a representative example, my existing create
action:
class GamesController < ApplicationController
def create
@game = Game.params[:new]
if @game.random_create
# Asked to create a game using random choices.
# Make the random choices, then present it to the user for tweaking
@game.expand_random_choices
render :action => new
else
# Fully specified. Create the game
begin
@game.save!
# ...other work including DB operations ...
flash[:notice] += 'Game was successfully created.'
redirect_to :action => :play, :id => @game
rescue ActiveRecord::RecordInvalid
@game.valid?
render :action => 'new'
end
end
end
end
I now have my PbemController for handling Cloudmailin emails:
class PbemController < ApplicationController
# Handle inbound email
def handle
if email_is_a_game_creation
...
end
render :text => "Handled"
end
end
What the best and DRYest way to invoke the existing create
behaviour from the PbemController
? Is my only real option extracting each "shared" action to a module in /lib' and
include`ing that in each controller?