Forum: Ruby on Rails form_for with nested shallow route

Posted by Alex (Guest)
on 2010-03-24 02:23
(Received via mailing list)
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)
Please log in before posting. Registration is free and takes only a minute.
Existing account (Switch to SSL-encrypted connection)
NEW: Do you have a Google/GoogleMail or Yahoo account? No registration required!
Log in with Google account | Log in with Yahoo account
No account? Register here.