# Using form\_for in a partial

**URL:** <https://www.ruby-forum.com/t/using-form-for-in-a-partial/183086>\
**Category:** Rails\
**Created:** [February 7, 2010, 9:23pm UTC](https://www.ruby-forum.com/t/using-form-for-in-a-partial/183086 "2010-02-07T21:23:47Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![b1gtuna](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/8dc957/32.png) [@b1gtuna](https://www.ruby-forum.com/u/b1gtuna)\
**Post date:** [February 7, 2010, 9:23pm UTC](https://www.ruby-forum.com/t/using-form-for-in-a-partial/183086/1 "2010-02-07T21:23:47Z")

</div>

Hello,

I would like a user to fill out a form (a long contract) and then email  
it to them, including the new values.

So I was leaning towards a partial or layout so I didn’t have to write  
the contract twice. But that’s where I run into problems. The only  
difference between the form (contract) and the email are the form tags  
will be replaced with their actual values. For example:

My HTML Contract  
\<% form\_for @contract, :url =\> { :action =\> “send\_contract”} do |f| %\>  
\<%= f.error\_messages %\>

 Lots of text that I don't want to duplicate 

 \<%= f.label :name, "Name: " %\> \<%= f.text\_field :name %\> 

 \<%= f.label :email, "Email: " %\> \<%= f.text\_field :email %\> 

 Lots more text that I don't want to duplicate 
 ... \<% end %\>

My Email Contract

 Lots of text that I don't want to duplicate

 \<%= "Name: " %\> \<%= @email[:name] %\>

 \<%= "Email: " %\> \<%= @email[:name] %\>

 Lots more text that I don't want to duplicate

My goal:  
\<% if params[:action] == “contract” %\>  
\<% form\_for @contract, :url =\> { :action =\> “send\_contract”} do |f| %\>  
\<%= f.error\_messages %\>  
\<% end %\>

 Lots of text that I don't want to duplicate

 \<% if params[:action] == "contract" %\> \<%= f.label :name, "Name: " %\> \<%= f.text\_field :name %\> \<% else %\> \<%= "Name: " %\> \<%= @email[:name] %\> \<% end %\>

 \<% if params[:action] == "contract" %\> \<%= f.label :email, "Email: " %\> \<%= f.text\_field :email %\> \<% else %\> \<%= "Email: " %\> \<%= @email[:name] %\> \<% end %\>

 Lots more text that I don't want to duplicate
\<% if params[:action] == "contract" %\> \<% end %\> \<% end %\>

Obviously, this doesn’t work. Any ideas on how to leverage the shared  
text while still maintaining a form? I know I could use the form\_tag  
instead, but that wouldn’t give me all the needed stuff that comes  
with the form\_for tag.

Adam
