session based solution
With such deeply nested models, selecting a box at the front end will not be enough ... Assuming this, you might want to create a current_house that id lives in the session (how current_user works).
After your current_house will add different items by going through the list of items list and clicking the add_to link:
# house_controller.rb def add_to current_house.polymorphic_items << Kitchen.find(params[:id]) redirect_to :back end
But there are many approaches to this session-based solution that implements a cart / order system. You can add current_item to add material to each leaf of your tree in the room of your house.
EG after clicking on the newly added kitchen:
before_filter :set_current_item def add_to current_item.windows << Window.find(id) end
current_item beeing polymorphic: living room, bathroom, etc. But how you implement this, it depends on your domain model ....
As a rule, with regard to nested forms, I will follow the directions of the guides for the routes: do not go down a single level, otherwise you will be in a mess.
source share