Browse Source

tweaks, contact form

pull/1/head
Nicolae Claudius 13 years ago
parent
commit
bd6d8fc34e
  1. 1
      app/assets/stylesheets/application.css
  2. 4
      app/assets/stylesheets/pages/contact.css.scss
  3. 12
      app/assets/stylesheets/theme/error_explanation.css.scss
  4. 16
      app/controllers/pages_controller.rb
  5. 18
      app/helpers/application_helper.rb
  6. 17
      app/mailers/contact_form.rb
  7. 1
      app/views/devise/registrations/edit.html.erb
  8. 5
      app/views/pages/contact.html.erb
  9. 30
      app/views/pages/contact/_form.html.erb
  10. 1
      config/routes.rb
  11. 1
      config/settings.sample.yml

1
app/assets/stylesheets/application.css

@ -15,6 +15,7 @@
*= require pages/team
*= require pages/help
*= require pages/edit_account
*= require pages/contact
*= require active_scaffold
*= require overrides

4
app/assets/stylesheets/pages/contact.css.scss

@ -0,0 +1,4 @@
.send-contact-form {
font-size: 1.2em;
font-weight: bold;
}

12
app/assets/stylesheets/theme/error_explanation.css.scss

@ -1,14 +1,24 @@
@import 'compass/css3/border-radius';
@import 'compass/css3/text-shadow';
#main .block .content #error_explanation {
#main .block .content {
#error_explanation {
@include border-top-radius(6px);
border-left: 1px solid #993624;
border-right: 1px solid #993624;
border-bottom: 1px solid #993624;
h2 {
background-color: #cc4831;
color: white;
padding: 10px 15px;
margin: 0;
@include text-shadow(none);
@include border-top-radius(6px);
}
}
.field_with_errors {
display: inline;
label {
color: #cc4831;
}

16
app/controllers/pages_controller.rb

@ -19,11 +19,21 @@ class PagesController < ApplicationController
end
def show
if user_signed_in? && params[:id] == "home"
redirect_to domains_path
else
return redirect_to(domains_path) if user_signed_in? && params[:id] == "home"
if params[:id] == "contact"
init = user_signed_in? ? {:name => current_user.name, :email => current_user.email} : {}
@contact_form = ContactForm.new(init)
end
render :template => current_page
end
def contact
@contact_form = ContactForm.new(params[:contact_form])
if !@contact_form.deliver
render :template => 'pages/contact'
else
redirect_to :back, :notice => 'Your notification has been sent!'
end
end
protected

18
app/helpers/application_helper.rb

@ -19,4 +19,22 @@ module ApplicationHelper
value.nil? ? nil : Time.at(value)
end
def error_messages_for(resource)
return "" if resource.errors.empty?
messages = resource.errors.full_messages.map { |msg| content_tag(:li, msg) }.join
sentence = I18n.t("errors.messages.not_saved",
:count => resource.errors.count,
:resource => resource.class.model_name.human.downcase)
html = <<-HTML
<div id="error_explanation">
<h2>#{sentence}</h2>
<ul>#{messages}</ul>
</div>
HTML
html.html_safe
end
end

17
app/mailers/contact_form.rb

@ -0,0 +1,17 @@
class ContactForm < MailForm::Base
attribute :name, :validate => true
attribute :email, :validate => true
attribute :message, :validate => true
attribute :file, :attachment => true, :allow_blank => true
attribute :nickname, :captcha => true # antispam
# Declare the e-mail headers. It accepts anything the mail method
# in ActionMailer accepts.
def headers
{
:subject => "#{name} Contact Form",
:to => Settings.support_mail,
:from => %("#{name}" <#{email}>)
}
end
end

1
app/views/devise/registrations/edit.html.erb

@ -43,7 +43,6 @@
</p>
</div>
</div>
</div>
</div>

5
app/views/pages/contact.html.erb

@ -5,9 +5,12 @@
<h1>Contact us</h1>
<p>
E-Mail address: <a href="mailto:support@entrydns.net">support@entrydns.net</a>
Our email address is <a href="mailto:support@entrydns.net">support@entrydns.net</a> ,
or you can contact us using the form below:
</p>
<%= render :partial => 'pages/contact/form' %>
</div>
</div>
</div>

30
app/views/pages/contact/_form.html.erb

@ -0,0 +1,30 @@
<%= form_for @contact_form, :url => {:action => 'contact'}, :method => 'post' do |f| %>
<%= error_messages_for(@contact_form) %>
<div style="display:none;">
<%= f.text_field :nickname %>
</div>
<p>
<%= f.label :name, 'Your name' %><br />
<%= f.text_field :name %>
</p>
<p>
<%= f.label :email, 'Your email' %><br />
<%= f.text_field :email %>
</p>
<p>
<%= f.label :file %> <i>can be attached optionally</i><br />
<%= f.file_field :file %>
</p>
<p>
<%= f.label :message %><br />
<%= f.text_area :message, :rows => 10 %>
</p>
<p><%= f.submit 'Send', :class => 'send-contact-form' %></p>
<% end %>

1
config/routes.rb

@ -42,6 +42,7 @@ Entrydns::Application.routes.draw do
get '/dashboard', :to => 'dashboard#index', :as => :dashboard
resources :pages, :only => :show
post 'pages/contact', :to => 'pages#contact'
root :to => 'pages#show', :id => 'home'

1
config/settings.sample.yml

@ -14,3 +14,4 @@ protected_hostnames:
- smtp
- imap
- ns[0-9]*
support_mail: "support@entrydns.net"

Loading…
Cancel
Save