0
나는 일반적인 브라우저 기반 레일 게임 응용 프로그램을 개발했습니다. CloudMailin을 믹스에 추가하여 이메일을 통해 대체 인터페이스를 효과적으로 제공합니다.다른 컨트롤러 (CloudMailin)를 통해 "일반"컨트롤러 호출
class PbemController < ApplicationController
# Handle inbound email
def handle
if email_is_a_game_creation
...
end
render :text => "Handled"
end
end
는 최고의 DRYest 방법은 기존의를 호출 무엇 : 지금 Cloudmailin 이메일을 처리하기위한 제 PbemController이
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
:
은 대표적인 예로서, 기존 create
액션, 고려 create
동작이 PbemController
에서 발생합니까? 내 유일한 옵션은 각각의 컨트롤러에서 각각의 "공유"동작을 추출하여 /lib' and
에있는 모듈에 포함시키는 것입니까?
음, 내 컨트롤러에 너무 많은 비트가있을 것 같습니다. 내가 할 수 있는지 알게 될거야. – Chowlett
사실, 아니요, 리뷰에서 게임 로직의 대부분이 게임 모델에 있습니다. 컨트롤러 a)는 게임에게 무엇을 부탁 할 것인지 결정합니다. b) 게임보고 잘못된 매개 변수; c) 세션 사용자를 위해 새로운 플레이어와 새로운 플레이어를 연결하는 것을 처리한다. d) 플래시를 설정합니다. e) 렌더링 또는 재전송. 모델에 있어야 할 것 같은 기분이 들지 않습니다. – Chowlett
나에게 그것은 항목이 모델에 있어서는 안된다면 컨트롤러에서 메일 처리기 내에서 복제하지 않고이 장소의 메일 처리기에 특정한 코드를 추가하는 것일까? –