I'm building a rails app at the moment and am wondering if there is a way of simplifying the contact form process. Initially I was going to build a contact form for the home page, and a contact form for a 'become a partner' page. Each with their own controllers and html emails. However it got me wondering if there is a way of having only the one contact form and controller that generates the appropriate html email depending on which page it was submitted on? Basically I'd like the client to get an email with either, 'new message from home page' or 'new message from become a partner page'.
I'm sure there's a way but I'm having difficulty working out the relationship.
You can create a partial
_form.html.erb and call it wherever you want.
Inside your controller you can check from where request came by calling
home.html.erb could be
<HTML for home page> <%= render 'form' %> <more HTML for home page>
become_a_partner.html.erb could be
<HTML for partner page> <%= render 'form' %> <more HTML for partner page>
_form.html.erb could be
<%= form_for(@contact) do |f| %> <%= f.text_field :nome %> <%= f.text_field :email %> <%= f.text_area :message %> <% end %>
And finally you can check from where request came so that you can set proper message.