我开发了一个普通的基于浏览器的 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
我现在有我的 PbemController 来处理 Cloudmailin 电子邮件:
class PbemController < ApplicationController
# Handle inbound email
def handle
if email_is_a_game_creation
...
end
render :text => "Handled"
end
end
create
从PbemController
? _ 我唯一真正的选择是将每个“共享”动作提取到一个模块中,/lib' and
并将其包含在每个控制器中吗?