# Reusing trhe same form as partial for add and update

**URL:** <https://www.ruby-forum.com/t/reusing-trhe-same-form-as-partial-for-add-and-update/124576>\
**Category:** Rails\
**Created:** [December 30, 2007, 1:53pm UTC](https://www.ruby-forum.com/t/reusing-trhe-same-form-as-partial-for-add-and-update/124576 "2007-12-30T13:53:57Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![adam](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/4af34b/32.png) [@adam](https://www.ruby-forum.com/u/adam)\
**Post date:** [December 30, 2007, 1:53pm UTC](https://www.ruby-forum.com/t/reusing-trhe-same-form-as-partial-for-add-and-update/124576/1 "2007-12-30T13:53:57Z")

</div>

HI!  
I have a form which I want to reuse for adding and updating a user.  
The thing is I have 3 models in it  
user, address, phone

in the manage view I have

\<% if params[:id].blank? -%\>  
\<%form\_for :user, :url=\>{:action=\>:register} do |form| %\>  
\<%= render :partial=\>‘form’, :locals =\> { :form =\> form }%\>

 \<%= submit\_tag "rejestruj"%\> \<%end%\> \<%else -%\> \<%form\_for :user,@user, :url=\>{:action=\>:update,:id=\>@user.id} do | form| %\> \<%= render :partial=\>'form', :locals =\> { :form =\> form }%\> \<% end %\> \<%end%\>

so I’m adding the @user object. Is there a way to check inside the  
partial form if the user != nil  
and then do  
\<% fields\_for :address, @user.address do |a|%\>  
or  
\<% fields\_for :address do |a|%\>

I’ve tried it with if, ? : and so on but without any luck.

---

<div class="post-metadata">

**Author:** ![adam](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/4af34b/32.png) [@adam](https://www.ruby-forum.com/u/adam)\
**Post date:** [December 30, 2007, 2:05pm UTC](https://www.ruby-forum.com/t/reusing-trhe-same-form-as-partial-for-add-and-update/124576/2 "2007-12-30T14:05:06Z")

</div>

Never mind, I’ve got it 🙂

Just made antoher partial for the address and the same way as the main  
form with  
\<% if @user %\>  
\<% fields\_for :address, @user.address do |a|%\>  
\<%= render :partial=\>‘address’,:locals=\>{:a =\> a} %\>  
\<%end%\>  
\<%else %\>  
\<% fields\_for :address do |a|%\>  
\<%= render :partial=\>‘address’,:locals=\>{:a =\> a} %\>  
\<%end%\>  
\<%end%\>

Sorry for such quick question
