Reputation: 1834
I have a working form that posts to a controller to send an email.
Controller:
def contact
name = params[:contact][:your_name]
message = params[:contact][:your_message]
email = params[:contact ][:your_email]
Contact.contact_form(message, name, email).deliver
redirect_to :back
end
Form:
<%= form_for :contact , :url => contact_pages_path(@message), :html => {:method => :put} do |f| %>
<p>
<b>Your email:</b><br>
<%= f.text_field :your_email %>
<b>Name</b><br>
<%= f.text_field :your_name %>
</p>
<p>
<b>Message</b><br>
<%= f.text_area :your_message %>
</p>
<p>
However I am not very happy with the
redirect_to :back
As it just reloads the page. How can I flash a message up afterwards saying "Thankyou" without moving away from the page? The message could even appear in the form - so afterwards a box appears saying - "Thanks"
Upvotes: 0
Views: 295
Reputation: 653
I am not sure but could you please try this?
if Contact.contact_form(message, name, email).deliver
flash[:notice] = "mail has been sent successfully."
I think you may be don't have to redirect to anywhere. Hope it will help.
Upvotes: 0
Reputation: 8372
redirect_to :back, :notice => "Thank-you"
Of course, this will only work if your application.html.erb
template is printing out the contents of notices/alerts. For that, you need something like:
<% if !notice.nil? || !alert.nil? %>
<section id="message" class="message-<%= notice.nil? ? "alert" : "notice" %>">
<div class="row">
<div>
<% if !notice.nil? %>
<p class="notice"><%= notice %></p>
<% end %>
<% if !alert.nil? %>
<p class="alert"><%= alert %></p>
<% end %>
</div>
</div>
</section>
<% end %>
Upvotes: 1