I am getting an OpenSSL::SSL::SSLError when I try to send an email via my contact form.
In my config/application.rb I have addded.
config.action_mailer.raise_delivery_errors = true
config.action_mailer.delivery_method = :smtp
ActionMailer::Base.smtp_settings = {
:address => "mail.vinderhimlen.dk",
:port => 587,
:user_name => "asd#vinderhimlen.dk",
:password => "x",
:authentication => :login
}
My form:
<%= simple_form_for [#support], :url => { :action => "create" }, :html => { :method => :post } do |f| %>
<%= f.input :sender_name, :label => 'Navn' %>
<%= f.input :email, :label => 'E-mail' %>
<%= f.input :support_type, :collection => ['Feedback', 'Idé', "Rapporter fejl", 'Business', 'Andet'], :prompt => "Valg type", :label => 'Erinde' %>
<%= f.label :Besked %>
<%= f.text_area :content, :label => 'Besked', :style => 'width:500px;', %>
<%= f.submit "submit", :value => 'Send besked' %>
<% end %>
My Supportscontroller:
class SupportsController < ApplicationController
def new
# id is required to deal with form
#support = Support.new(:id => 1)
end
def create
#support = Support.new(params[:support])
if #support.save
redirect_to('/', :notice => "Support was successfully sent.")
else
flash[:alert] = "You must fill all fields."
render 'new'
end
end
end
My Support model:
class Support
include ActiveModel::Validations
validates_presence_of :email, :sender_name, :support_type, :content
# to deal with form, you must have an id attribute
attr_accessor :id, :email, :sender_name, :support_type, :content
def initialize(attributes = {})
attributes.each do |key, value|
self.send("#{key}=", value)
end
#attributes = attributes
end
def read_attribute_for_validation(key)
#attributes[key]
end
def to_key
end
def save
if self.valid?
Notifier.support_notification(self).deliver
return true
end
return false
end
end
My config/enviroments/devolpment:
Konkurranceportalen::Application.configure do
# Settings specified here will take precedence over those in config/application.rb
# In the development environment your application's code is reloaded on
# every request. This slows down response time but is perfect for development
# since you don't have to restart the webserver when you make code changes.
config.cache_classes = false
# Log error messages when you accidentally call methods on nil.
config.whiny_nils = true
config.perform_delivery = true
# Show full error reports and disable caching
config.consider_all_requests_local = true
config.action_view.debug_rjs = true
config.action_controller.perform_caching = false
# Don't care if the mailer can't send
config.action_mailer.raise_delivery_errors = true
# Print deprecation notices to the Rails logger
config.active_support.deprecation = :log
# Only use best-standards-support built into browsers
config.action_dispatch.best_standards_support = :builtin
end
My rails log on when submitting the form:
Started POST "/supports" for 127.0.0.1 at 2011-05-31 14:07:07 +0200
Processing by SupportsController#create as HTML
Parameters: {"utf8"=>"Ô£ô", "authenticity_token"=>"b4ILe7Xu4moToY8PN1X4wdyejz6
DQwnZ69FPevAWuSI=", "support"=>{"sender_name"=>"dfsdf", "email"=>"mail#freelance
rbasen.dk", "support_type"=>"Feedback", "content"=>"dsdsfsdfsdfsdfsdfsadasdasd"}
, "commit"=>"Send besked"}
←[1m←[36mSQL (0.0ms)←[0m ←[1mSELECT SUM(`tags`.`konkurrancers_count`) AS sum_
id FROM `tags`←[0m
←[1m←[35mSQL (10.0ms)←[0m describe `kategoris_konkurrancers`
←[1m←[36mKonkurrancer Load (0.0ms)←[0m ←[1mSELECT `konkurrancers`.* FROM `kon
kurrancers`←[0m
←[1m←[35mCACHE (0.0ms)←[0m SELECT `konkurrancers`.* FROM `konkurrancers`
←[1m←[36mTag Load (1.0ms)←[0m ←[1mSELECT `tags`.* FROM `tags`←[0m
Rendered notifier/support_notification.html.erb (1.0ms)
Sent mail to asd#vinderhimlen.dk (277ms)
Date: Tue, 31 May 2011 14:07:08 +0200
From: asd#freelancerbasen.dk
To: asd#vinderhimlen.dk
Message-ID: <4de4d9ecc67fdsfsdfsdf4ad#Home-Pc.mail>
Subject: New Feedback
Mime-Version: 1.0
Content-Type: text/html;
charset=UTF-8
Content-Transfer-Encoding: quoted-printable
=EF=BB=BFhello world!
dsdsfsdfsdfsdfsdfsadasdasd=
Completed in 865ms
OpenSSL::SSL::SSLError (hostname was not match with the server certificate):
app/models/support.rb:24:in `save'
app/controllers/supports_controller.rb:9:in `create'
Rendered C:/Ruby192/lib/ruby/gems/1.9.1/gems/actionpack-3.0.3/lib/action_dispatc
h/middleware/templates/rescues/_trace.erb (1.0ms)
←[1m←[35mKonkurrancer Load (1.0ms)←[0m SELECT `konkurrancers`.* FROM `konkurr
ancers` LIMIT 15 OFFSET 0
←[1m←[36mSQL (4.0ms)←[0m ←[1mSHOW TABLES←[0m
←[1m←[35mSQL (5.0ms)←[0m SHOW TABLES
Rendered C:/Ruby192/lib/ruby/gems/1.9.1/gems/actionpack-3.0.3/lib/action_dispatc
h/middleware/templates/rescues/_request_and_response.erb (252.0ms)
Rendered C:/Ruby192/lib/ruby/gems/1.9.1/gems/actionpack-3.0.3/lib/action_dispatc
h/middleware/templates/rescues/diagnostics.erb within rescues/layout (318.0ms)
UPDATE:
In my config/application.rb:
config.action_mailer.smtp_settings = {:enable_starttls_auto => false }
config.action_mailer.raise_delivery_errors = true
config.action_mailer.delivery_method = :smtp
ActionMailer::Base.smtp_settings = {
:address => "mail.vinderhimlen.dk",
:port => 587,
:user_name => "asd#vinderhimlen.dk",
:password => "x",
:authentication => :login,
:domain => "vinderhimlen.dk",
:enable_starttls_auto => false
}
You could try
:openssl_verify_mode => 'none'
per Undocumented ActionMailer openssl_verify_mode option
Related
I am going through this tutorial (link:https://www.murdo.ch/blog/build-a-contact-form-with-ruby-on-rails-part-1) to create a simple contact us form on my existing rails application. After completing the tutorial and testing on my development environment I notice that my smtp settings are interferring with my contact us form. Basically I just want send a message to an email address so I dont need the sender mail address for this. I tried removing the SMTP settings in my development.rb file but then I get this error when clicking the submit button:
Errno::ECONNREFUSED in MessagesController#create
Connection refused - connect(2) for "localhost" port 1025
I tried solving in different ways but I come back to this same error. Here's my code:
model/message.rb:
class Message
include ActiveModel::Model
attr_accessor :name, :email, :body
validates :name, :email, :body, presence: true
end
Here's my message controller:
class MessagesController < ApplicationController
def new
#message = Message.new
end
def create
#message = Message.new message_params
if #message.valid?
MessageMailer.contact_me(#message).deliver_now
redirect_to new_message_url, notice: "Message received"
else
render :new
end
end
def message_params
params.require(:message).permit(:name, :email, :body)
end
end
My view:new.html.erb:
<%= form_for #message, url: create_message_url do |f| %>
<%= notice %>
<%= #message.errors.full_messages.join(', ') %>
<%= f.text_field :name, placeholder: 'name' %>
<%= f.email_field :email, placeholder: 'email' %>
<%= f.text_area :body, placeholder: 'body' %>
<%= f.submit 'Send' %>
<% end %>
My Mailer:
class MessageMailer < ApplicationMailer
def contact_me(message)
#greeting = 'Hi'
#body = message.body
mail to: "notifications#example.com", from: message.email
end
end
And my Development.rb/SMTP settings code:
config.action_mailer.delivery_method = :smtp
config.action_mailer.default_url_options = { host: 'localhost', port: 3000 }
config.action_mailer.perform_deliveries = true
config.action_mailer.raise_delivery_errors = true
config.action_mailer.default :charset => "utf-8"
config.action_mailer.smtp_settings = {
:address => 'localhost',
:port => 587,
:domain => 'localhost:3000',
:user_name => 'example#gmail.com',
:password => '######',
:authentication => 'plain',
:enable_starttls_auto => true
}
I just want to get rid of the smtp settings but unfortunately I cannot, is there any way to override these settings or an alternate solution or am I missing something,
Any help will be appreciated,
Thanks in advance
I got this problem of ActiveAdmin not updating my record and i noticed on log that the update statement is passing a PK key of "0" instead of the params[:id] of "5"... Any idea how can i override this? or any workaround? I was thinking maybe this was due to i was not using the normal PK of "id".. any thoughts? Thanks in advance...
Started PATCH "/admin/doctors/5" for 127.0.0.1 at 2014-09-15 20:51:35 +0800
Processing by Admin::DoctorsController#update as HTML
Parameters: {"utf8"=>"✓", "authenticity_token"=>"rkmUILbx/t6Rk5jtanupJkt5yZBmj6PbGQhnhxcOP0U=", "doctor"=>{ "gender"=>"0", "details"=>"asdfasdf", "active_flag"=>"Y"}, "commit"=>"Update Doctor", "id"=>"5"}
AdminUser Load (0.4ms) SELECT `admin_users`.* FROM `admin_users` WHERE `admin_users`.`id` = 2 ORDER BY `admin_users`.`id` ASC LIMIT 1
Doctor Load (0.2ms) SELECT `doctors`.* FROM `doctors` WHERE `doctors`.`doctor_id` = ? LIMIT 1 [["doctor_id", 5]]
SQL (0.7ms) BEGIN
SQL (0.3ms) UPDATE `doctors` SET `gender` = ?, `updated_at` = ? WHERE `doctors`.`doctor_id` = 0 [["gender", 0], ["updated_at", "2014-09-15 12:51:35"]]
(0.6ms) COMMIT
Redirected to http://localhost:3000/admin/doctors/5
Completed 302 Found in 40ms (ActiveRecord: 2.2ms)
Started GET "/admin/doctors/5" for 127.0.0.1 at 2014-09-15 20:51:35 +0800
Processing by Admin::DoctorsController#show as HTML
Parameters: {"id"=>"5"}
AdminUser Load (0.3ms) SELECT `admin_users`.* FROM `admin_users` WHERE `admin_users`.`id` = 2 ORDER BY `admin_users`.`id` ASC LIMIT 1
Doctor Load (0.3ms) SELECT `doctors`.* FROM `doctors` WHERE `doctors`.`doctor_id` = ? LIMIT 1 [["doctor_id", 5]]
Completed 200 OK in 25ms (Views: 20.9ms | ActiveRecord: 0.6ms)
Here the controller code..
ActiveAdmin.register Doctor do
controller do
def permitted_params
params.permit :utf8, :_method, :authenticity_token, :commit, :id, :doctor_id,
doctor: [:first_name, :middle_initial, :last_name, :name_suffix,
:title, :primary_spec_id, :dob, :gender, :email, :phone,
:details, :ratings, :active_flag ]
end
def update
params.merge!({doctor_id: params[:id]})
Rails.logger.debug params.inspect
super
end
end
menu parent: 'Maintenance Tables'
scope :is_inactive
scope :is_active
filter :first_name
filter :last_name
filter :email
filter :primary_spec_id, :label => 'Specialization' , :as => :select , :collection => Specialization.all.order(name: :asc)
filter :gender, :as => :select , :collection => { 'Male' => 1, 'Female' => 0 }
filter :active_flag, :label => 'Status' , :as => :select , :collection => ['Y','N']
index do
column :ID, :sortable => :doctor_id, :max_width => "500px" do |doctor|
link_to(doctor.doctor_id, admin_doctor_path(doctor))
end
column :first_name
column :M_I, :sortable => :middle_initial do |doctor|
doctor.middle_initial
end
column :last_name
column :suffix, :sortable => :name_suffix do |doctor|
doctor.name_suffix
end
column :title
column :specialization, :sortable => :primary_spec_id do |doctor|
specialization = Specialization.find(doctor.primary_spec_id)
link_to(specialization.name,admin_specialization_path(specialization))
end
column :dob
column :gender, :sortable => :gender do |doctor|
gender = ['F','M']
gender[doctor.gender]
end
column :email, :sortable => :email do |doctor|
mail_to(doctor.email)
end
column :phone
column :active_flag, :sortable => :active_flag do |doctor|
div :class => "doctor_status" do
status_tag(doctor.active_flag, ((doctor.active_flag == 'Y') ? :ok : :error))
end
end
end
form do |f|
f.inputs "Doctor Details" do
#f.input :doctor_id
f.input :first_name
f.input :middle_initial, :label => 'M.I.'
f.input :last_name
f.input :name_suffix, :label => 'Suffix', :as => :select, :collection => ['JR.', 'SR.', 'III', 'IV', 'V']
f.input :title, :label => 'Specialization Title Prefix', :hint => "(e.g. M.D., etc.)"
f.input :primary_spec_id, :as => :select, :collection => Specialization.all.order(name: :asc)
f.input :dob, :label => 'Birth Date', :hint => "(format: MM/DD/YYYY)"
f.input :gender, :as => :radio, :collection => { 'M' => 1, 'F' => 0 }
f.input :email, :as => :email
f.input :phone, :as => :phone
f.input :details, :label => 'Doctor\'s Brief Description', :as => :text
f.input :picture, :label => 'Upload Picture', :as => :file
f.input :active_flag, :as => :select, :collection => ['Y','N'], :hint => "(Default: Y)"
end
f.actions
end
end
Do you get the same error, if you permit the id of the doctor like this?
doctor: [:id, :first_name, :middle_initial, :last_name, :name_suffix,
:title, :primary_spec_id, :dob, :gender, :email, :phone,
:details, :ratings, :active_flag ]
Finally figured it out. Maybe it was something to do with the ActiveRecord the Rails version 4.1.6..
So I tried reverting my gem to 4.0.4
gem 'rails', '4.0.4'
Then it finally working as it should be.. Thanks anyway..
Started PATCH "/admin/doctors/5" for 127.0.0.1 at 2014-09-16 17:24:19 +0800
Processing by Admin::DoctorsController#update as HTML
Parameters: {"utf8"=>"✓", "authenticity_token"=>"I9K+GM6iB1a9OvKvmFrqz3qsf4XwedImLHYihtxYBKY=", "doctor"=>{ "gender"=>"0", "details"=>"asdfasdf", "active_flag"=>"Y"}, "commit"=>"Update Doctor", "id"=>"5"}
AdminUser Load (3.9ms) SELECT `admin_users`.* FROM `admin_users` WHERE `admin_users`.`id` = 2 ORDER BY `admin_users`.`id` ASC LIMIT 1
Doctor Load (1.2ms) SELECT `doctors`.* FROM `doctors` WHERE `doctors`.`doctor_id` = ? LIMIT 1 [["doctor_id", "5"]]
SQL (0.1ms) BEGIN
SQL (0.4ms) UPDATE `doctors` SET `gender` = ?, `updated_at` = ? WHERE `doctors`.`doctor_id` = 5 [["gender", 0], ["updated_at", Tue, 16 Sep 2014 09:24:19 UTC +00:00]]
(0.6ms) COMMIT
Redirected to http://localhost:3000/admin/doctors/5
Completed 302 Found in 33ms (ActiveRecord: 6.3ms)
First off, i know attr_accessible is deprecated in Rails 4, but what about attr_accessor?
When you hit submit it's returning a "Template is Missing" error, but that's because its hitting an error somewhere in the send proccess then just trying to return "connect#create" which doesn't exist as a physical page.
When i check the log files, I am getting a 500 internal server error when trying to send a contact form, and I'm not sure if using attr_accessor in Rails 4 is the culprit. Is there a newer way to write this?
class Message
include ActiveModel::Validations
include ActiveModel::Conversion
extend ActiveModel::Naming
attr_accessor :name, :email, :phone, :subject, :company, :title, :market, :body
validates :name, :email, :subject, :company, :body, :presence => true
validates :email, :format => { :with => %r{.+#.+\..+} }, :allow_blank => true
def initialize(attributes = {})
attributes.each do |name, value|
send("#{name}=", value)
end
end
def persisted?
false
end
end
The above is the message model for the contact form:
Is it something within the process of sending the data?
The rest of the code for the contact mail functionality is:
Contact Mailer
class ContactMailer< ActionMailer::Base
default :from => "noreply#test.com"
default :to => "{{MY EMAIL}}"
def new_message(message)
#message = message
mail(:subject => "Test Message")
end
end
In /views/contact_mailer/ there is a new_message.text.erb file:
Name: <%= #message.name %>
Email: <%= #message.email %>
Phone: <%= #message.phone %>
Subject: <%= #message.subject %>
Company: <%= #message.company %>
Title: <%= #message.title %>
Market: <%= #message.market %>
Body: <%= #message.body %>
My Routes are:
match 'connect' => 'connect#index', :as => 'connect', :via => :get
match 'connect' => 'connect#create', :as => 'connectpost', :via => :post
The connect page controller:
class ConnectController < ApplicationController
def index
#message = Message.new
end
def create
#message = Message.new(params[:message])
if #message.valid?
NotificationsMailer.new_message(#message).deliver
redirect_to(connect_path, :notice => "Message was successfully sent.")
else
flash.now.alert = "Please fill all fields."
render :new
end
end
end
And finally....the SMTP settings in /config/initializers/smtp_settings.rb
ActionMailer::Base.smtp_settings = {
:address => "smtp.gmail.com",
:port => 587,
:domain => "{{SITE DOMAIN}}",
:user_name => "{{GMAIL EMAIL}}",
:password => "{{GMAIL EMAIL PASSWORD}}",
:authentication => "plain",
:enable_starttls_auto => true
}
My ConnectController#Create was trying to initialize
NotificationMailers.new_message()
But it needed to be:
ContactMailer.new_message()
I have no idea why the tutorial I followed would have the wrong class name there...but that was the issue.
Thanks all.
attr_accessor, attr_writer and attr_reader are all part of vanilla core Ruby and are helper methods for Modules and Classes.
They work fine in Ruby 2.0, so you'll have to mark them off your suspect list.
Using Ryan Bate's RailsCasts #124 Beta Invites (as well as the updated rails 3.1 api) as a crutch, I'm trying to put together my first piece of Action Mailer functionality: inviting someone to collaborate with you on a project.
My issue is that the :recipient_email isn't getting saved in the DB and I can't see what I'm missing.
config/initializers/setup_mail.rb
ActionMailer::Base.smtp_settings = {
:address => "smtp.gmail.com",
:port => 587,
:domain => 'blah.com',
:user_name => 'gmail username',
:password => 'gmail password',
:authentication => 'plain',
:enable_starttls_auto => true
}
ActionMailer::Base.register_interceptor(DevelopmentMailInterceptor) if Rails.env.development?
app/models/invitation.rb
class Invitation < ActiveRecord::Base
email_regex = /\A[\w+\-.]+#[a-z\d\-.]+\.[a-z]+\z/i
attr_accessor :recipient_email
belongs_to :sender, :class_name => "User", :foreign_key => "sender_id"
has_one :recipient, :class_name => "User", :foreign_key => "recipient_id"
validates_presence_of :recipient_email, :on => :create, :message => "can't be blank"
validates :recipient_email, :format => email_regex
validate :recipient_is_not_registered
before_create :generate_token
def sender_name
sender.user_name
end
def sender_email
sender.email
end
private
def recipient_is_not_registered
exsisting_user = User.find_by_email(recipient_email)
if exsisting_user
errors.add :recipient_email, 'is already a member.'
else
recipient_email
end
end
def generate_token
self.token = Digest::SHA1::hexdigest([Time.now, rand].join)
end
end
app/models/user.rb (minus all the auth stuff)
class User < ActiveRecord::Base
attr_accessible :invitation_token
has_many :sent_invitations, :class_name => "Invitation", :foreign_key => "sender_id"
belongs_to :invitation
end
app/controller/invitations_controller.rb
class InvitationsController < ApplicationController
before_filter :authenticate
def new
#title = "Invite client"
#invitation = current_user.sent_invitations.new
end
def create
#invitation = current_user.sent_invitations.create!(params[:invitation])
sender_name = #invitation.sender_name
sender_email = #invitation.sender_email
if #invitation.save
Mailer.invitation(#invitation, signup_url(#invitation.token), sender_name, sender_email).deliver
flash[:success] = "Your client has been sent the email. Why not create a booking for them?"
redirect_to bookings_path
else
#title = "Invite client"
render :new
end
end
end
app/mailers/mailer.rb
def invitation(invitation, signup_url, sender_name, sender_email)
#signup_url = signup_url
#sender_name = sender_name
#sender_email = sender_email
mail(:to => invitation.recipient_email,
:subject => "Invitation to Join",
:from => #sender_email)
end
app/views/invitations/_invitation_form.html.erb
<%= form_for #invitation do |f| %>
<%= render 'shared/error_messages', :object => f.object %>
<%= f.hidden_field :email_token %>
<br />
<div class="field">
<%= f.label :recipient_email, "Client's email address" %>
<%= f.email_field :recipient_email %>
</div>
<br />
<div class="action">
<%= f.submit "Send invitation", :class => "a small white button radius" %>
</div>
<% end %>
The SQL log showing that the :recipient_email isn't getting saved
Started POST "/invitations" for 127.0.0.1 at 2011-12-14 21:27:11 +1100
Processing by InvitationsController#create as HTML
Parameters: {"utf8"=>"✓", "authenticity_token"=>"7/SGZypGXtf9ShlcjC6o8ZRj2Qe4OJTHdjis2/m3ulc=", "invitation"=>{"recipient_email"=>"users#email.com"}, "commit"=>"Send invitation"}
User Load (0.2ms) SELECT "users".* FROM "users" WHERE "users"."id" = 1 LIMIT 1
(0.1ms) BEGIN
User Load (0.3ms) SELECT "users".* FROM "users" WHERE "users"."email" = 'users#email.com' LIMIT 1
SQL (0.4ms) INSERT INTO "invitations" ("created_at", "recipient_email", "sender_id", "sent_at", "token", "updated_at") VALUES ($1, $2, $3, $4, $5, $6) RETURNING "id" [["created_at", Wed, 14 Dec 2011 10:27:11 UTC +00:00], ["recipient_email", nil], ["sender_id", 1], ["sent_at", nil], ["token", "56fba1647d40b53090dd49964bfdf060228ecb2d"], ["updated_at", Wed, 14 Dec 2011 10:27:11 UTC +00:00]]
(10.2ms) COMMIT
User Load (0.3ms) SELECT "users".* FROM "users" WHERE "users"."id" = 1 LIMIT 1
(0.1ms) BEGIN
User Load (0.2ms) SELECT "users".* FROM "users" WHERE "users"."email" = 'users#email.com' LIMIT 1
(0.1ms) COMMIT
Rendered mailer/invitation.text.erb (0.4ms)
Sent mail to users#email.com (7ms)
Date: Wed, 14 Dec 2011 21:27:11 +1100
From: admin#email.com
It's probably the attr_accessor :recipient_email line in your Invitation model. Take that line out as recipient_email is a database field, ain't it?
I am trying to create a contact the form gets submitted. But I don't receive any email.
In my config/application.rb I have addded.
config.action_mailer.raise_delivery_errors = true
config.action_mailer.delivery_method = :smtp
ActionMailer::Base.smtp_settings = {
:address => "mail.vinderhimlen.dk",
:port => 587,
:user_name => "asd#vinderhimlen.dk",
:password => "x",
:authentication => :login
}
My form:
<%= simple_form_for [#support], :url => { :action => "create" }, :html => { :method => :post } do |f| %>
<%= f.input :sender_name, :label => 'Navn' %>
<%= f.input :email, :label => 'E-mail' %>
<%= f.input :support_type, :collection => ['Feedback', 'Idé', "Rapporter fejl", 'Business', 'Andet'], :prompt => "Valg type", :label => 'Erinde' %>
<%= f.label :Besked %>
<%= f.text_area :content, :label => 'Besked', :style => 'width:500px;', %>
<%= f.submit "submit", :value => 'Send besked' %>
<% end %>
My Supportscontroller:
class SupportsController < ApplicationController
def new
# id is required to deal with form
#support = Support.new(:id => 1)
end
def create
#support = Support.new(params[:support])
if #support.save
redirect_to('/', :notice => "Support was successfully sent.")
else
flash[:alert] = "You must fill all fields."
render 'new'
end
end
end
My Support model:
class Support
include ActiveModel::Validations
validates_presence_of :email, :sender_name, :support_type, :content
# to deal with form, you must have an id attribute
attr_accessor :id, :email, :sender_name, :support_type, :content
def initialize(attributes = {})
attributes.each do |key, value|
self.send("#{key}=", value)
end
#attributes = attributes
end
def read_attribute_for_validation(key)
#attributes[key]
end
def to_key
end
def save
if self.valid?
Notifier.support_notification(self).deliver
return true
end
return false
end
end
My config/enviroments/devolpment:
Konkurranceportalen::Application.configure do
# Settings specified here will take precedence over those in config/application.rb
# In the development environment your application's code is reloaded on
# every request. This slows down response time but is perfect for development
# since you don't have to restart the webserver when you make code changes.
config.cache_classes = false
# Log error messages when you accidentally call methods on nil.
config.whiny_nils = true
config.perform_delivery = true
# Show full error reports and disable caching
config.consider_all_requests_local = true
config.action_view.debug_rjs = true
config.action_controller.perform_caching = false
# Don't care if the mailer can't send
config.action_mailer.raise_delivery_errors = true
# Print deprecation notices to the Rails logger
config.active_support.deprecation = :log
# Only use best-standards-support built into browsers
config.action_dispatch.best_standards_support = :builtin
end
My rails log on when submitting the form:
Started POST "/supports" for 127.0.0.1 at 2011-05-31 11:15:35 +0200
Processing by SupportsController#create as HTML
Parameters: {"utf8"=>"Ô£ô", "authenticity_token"=>"bn05TaU4o6TwLVwYH0PgnDyYouo
P1HptzW3HHY2QV/s=", "support"=>{"sender_name"=>"asdasd", "email"=>"ssad#sazdasd.
dk", "support_type"=>"Id├®", "content"=>"asdasd"}, "commit"=>"Send besked"}
←[1m←[36mSQL (0.0ms)←[0m ←[1mSELECT SUM(`tags`.`konkurrancers_count`) AS sum_
id FROM `tags`←[0m
←[1m←[35mSQL (8.0ms)←[0m describe `kategoris_konkurrancers`
←[1m←[36mKonkurrancer Load (1.0ms)←[0m ←[1mSELECT `konkurrancers`.* FROM `kon
kurrancers`←[0m
←[1m←[35mCACHE (0.0ms)←[0m SELECT `konkurrancers`.* FROM `konkurrancers`
←[1m←[36mTag Load (1.0ms)←[0m ←[1mSELECT `tags`.* FROM `tags`←[0m
Rendered notifier/support_notification.html.erb (1.0ms)
Sent mail to asd#vinderhimlen.dk (1752ms)
Date: Tue, 31 May 2011 11:15:39 +0200
From: ssad#sazdasd.dk
To: asd#vinderhimlen.dk
Message-ID: <4asdqweb124ce_16cc85248bc677b3#Home-Pc.mail>
Subject: =?UTF-8?Q?New_Id=C3=A9?=
Mime-Version: 1.0
Content-Type: text/html;
charset=UTF-8
Content-Transfer-Encoding: quoted-printable
=EF=BB=BFhello world!
asdasd=
Redirected to http://localhost:3000/
Completed 302 Found in 4503ms
To trigger mails in dev mode, add this to your development.yml file:
config.action_mailer.perform_deliveries = true