私は通常のブラウザベースのRailsゲームアプリケーションを開発しました。現在、CloudMailinをミックスに追加して、電子メールを介して代替インターフェースを効果的に公開しています。
代表的な例として、私の既存のcreate
行動を考えてみましょう。
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
これで、Cloudmailinメールを処理するためのPbemControllerができました。
class PbemController < ApplicationController
# Handle inbound email
def handle
if email_is_a_game_creation
...
end
render :text => "Handled"
end
end
create
から既存の動作を呼び出すための最良かつ最も乾燥した方法は何PbemController
ですか?私の唯一の本当の選択肢は、各「共有」アクションをモジュールに/lib' and
抽出し、それを各コントローラーに含めることですか?