我有一個軌道控制器顯示操作,顯示團隊的父母團隊,團隊的孩子團隊或完整的家庭樹。目前我正在做這個簡單的案例陳述。這是正確的「軌道」方式做或我應該重構?如果是的話,任何建議如何將不勝感激。有許多查詢參數的重構軌道控制器?
if @team= fetch_team
case params[:tree]
when 'parents'
@output = @team.ancestor_ids
when 'children'
@output = @team.child_ids
when 'full'
@output = @team.full_tree
when nil
@output = fetch_team
else
@output = {message: "requested query parameter: '#{params[:tree]}' not defined"}
end
render json: @output
else
render json: {message: "team: '#{params[:id]}' not found"}, status: 404
end
##
def fetch_team
Team.find_by(name: params[:id])
end
這是RAILS WAY爲此+1 – HackerKarma