我有一个轨道控制器显示操作,显示团队的父母团队,团队的孩子团队或完整的家庭树。目前我正在做这个简单的案例陈述。这是正确的“轨道”方式做或我应该重构?如果是的话,任何建议如何将不胜感激。有许多查询参数的重构轨道控制器?
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