# Best way to call action new for a child entity?

**URL:** <https://www.ruby-forum.com/t/best-way-to-call-action-new-for-a-child-entity/103338>\
**Category:** Rails\
**Created:** [May 4, 2007, 1:17pm UTC](https://www.ruby-forum.com/t/best-way-to-call-action-new-for-a-child-entity/103338 "2007-05-04T13:17:53Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![amiridis](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/73ab20/32.png) [@amiridis](https://www.ruby-forum.com/u/amiridis)\
**Post date:** [May 4, 2007, 1:17pm UTC](https://www.ruby-forum.com/t/best-way-to-call-action-new-for-a-child-entity/103338/1 "2007-05-04T13:17:53Z")

</div>

Hi,

I have two entities: Installation and Command. Each installation can  
have many commands. In order to create a command the user has to go  
through the installation. I have generated the standard scaffold code  
for command and I changed the two actions New and Create in the  
commands\_controller as follows:

def new  
session[:installation\_id] = params[:id] #I added this  
@command = Command.new  
end

def create  
@command = Command.new(params[:command])  
@installation = Installation.find(session[:installation\_id]) #I added  
this  
@command.installation = @installation #I added this  
if @command.save  
flash[:notice] = ‘Command was successfully created.’  
redirect\_to :action =\> ‘list’  
else  
render :action =\> ‘new’  
end  
end

In the installation list view I have a link for each listed installation  
that calls the command new action passing the installation id. In the  
new command action I save this id in the session and when create is  
called I retrieve the id and assign set the command to be relation with  
that installation.

Is this a good practice? Is there another maybe more proper way of doing  
what I did?

Thank you,  
Petros (A Ruby on Rails newbie)
