Using form_for in a partial

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

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs