# Form\_for with nested shallow route

**URL:** <https://www.ruby-forum.com/t/form-for-with-nested-shallow-route/185644>\
**Category:** Rails\
**Created:** [March 24, 2010, 2:23am UTC](https://www.ruby-forum.com/t/form-for-with-nested-shallow-route/185644 "2010-03-24T02:23:26Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![alex](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/db5fbb/32.png) [@alex](https://www.ruby-forum.com/u/alex)\
**Post date:** [March 24, 2010, 2:23am UTC](https://www.ruby-forum.com/t/form-for-with-nested-shallow-route/185644/1 "2010-03-24T02:23:26Z")

</div>

Let’s say I have:

map.resources :teams do |team|  
team.resources :squads, :shallow =\> true  
end

When I want to generate a form\_for a squad, I need both the team and  
squad for new/create, but only the squad for edit.

This means I need:

edit:  
form\_for(squad)

new:  
form\_for([team, squad])

This seems not very dry. Is there a more idiomatic way of doing this?

Right now, I’ve abbreviated to:

form\_for(team = team ? [team, squad] : squad)

(the team=team assignment makes sure there is no error if team is not  
defined)
