I'm really stuck here and am worried my mailer config files are all messed up. My app seems to work fine locally, I'm on Nitrous. I can git push heroku master fine and when opened can view the home page, which is just a form(https://nameless-taiga-1654.herokuapp.com/), however once I hit submit I get an error message. I believe all my mailer actions on nitrous are setup correctly, I was planning on using sendgrid via heroku to run the mailing side of things. Basically I'm just lost and need help. Attached are the heroku logs of the form error.
heroku logs -t
2015-08-07T11:00:54.501756+00:00 heroku[router]: at=info method=POST path="/contacts" host=nameless-taiga-1654.herokuapp.com request_id=452df9b2-aef8-4a23-9ffb-3ba6781d80
75 fwd="124.149.33.78" dyno=web.1 connect=1ms service=72ms status=500 bytes=1754
2015-08-07T11:00:54.433019+00:00 app[web.1]: Started POST "/contacts" for 124.149.33.78 at 2015-08-07 11:00:54 +0000
2015-08-07T11:00:54.437794+00:00 app[web.1]: Parameters: {"utf8"=>"✓", "authenticity_token"=>"Z2Qh/GDIycId0uJk2evhblbKisGXNlIzjtz+xfJoyac=", "contact"=>{"name"=>"John D
oe", "phone"=>"040000000", "email"=>"johndoe#gmail.com", "event_type"=>"Corporate", "comments"=>"Test Comments"}, "commit"=>"Submit"}
2015-08-07T11:00:54.491841+00:00 app[web.1]:
2015-08-07T11:00:54.491846+00:00 app[web.1]: Sent mail to justindavidson23#gmail.com (21.8ms)
2015-08-07T11:00:54.491848+00:00 app[web.1]: Completed 500 Internal Server Error in 53ms
2015-08-07T11:00:54.492821+00:00 app[web.1]:
2015-08-07T11:00:54.492824+00:00 app[web.1]: Errno::ECONNREFUSED (Connection refused - connect(2)):
2015-08-07T11:00:54.436340+00:00 app[web.1]: Processing by ContactsController#create as HTML
2015-08-07T11:00:54.492826+00:00 app[web.1]: app/mailers/contact_mailer.rb:8:in `contact_email'
2015-08-07T11:00:54.463333+00:00 app[web.1]: Rendered contact_mailer/contact_email.html.erb (0.3ms)
2015-08-07T11:00:54.492828+00:00 app[web.1]: app/controllers/contacts_controller.rb:9:in `create'
2015-08-07T11:00:54.492831+00:00 app[web.1]:
2015-08-07T11:00:54.492830+00:00 app[web.1]:
2015-08-07T11:00:54.492827+00:00 app[web.1]: app/models/contact.rb:7:in `send_email'
contacts_controller.rb
class ContactsController < ApplicationController
def new
#contact = Contact.new
end
def create
#contact = Contact.new(contact_params)
if #contact.save
flash[:success] = 'Message Sent.'
redirect_to new_contact_path
else
flash[:danger] = 'Error occurred, messgage not sent.'
redirect_to new_contact_path
end
end
end
models/contact.rb
class Contact < ActiveRecord::Base
validates :name, :email, presence: true
after_create :send_email
private
def send_email
ContactMailer.contact_email(self).deliver
end
end
mailers/contact_mailer.rb
class ContactMailer < ActionMailer::Base
default to: 'justindavidson23#gmail.com'
def contact_email(contact)
#contact = contact
mail(from: #contact.email, subject: 'Contact Form Message').deliver
end
end
views/contact_mailer/contact_email.html.erb
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<p>New Message from Hoot and Holla's Contact form, from <%= "#{#contact.name}, #{#contact.email}" %></p>
<p><%= #contact.phone %></p>
<p><%= #contact.event_type %></p>
<p><%= #contact.comments %></p>
</body>
</html>
application.html.erb
<!DOCTYPE html>
<html>
<head>
<title>HootandhollaLp</title>
<%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track' => true %>
<%= javascript_include_tag 'application', 'data-turbolinks-track' => true %>
<%= csrf_meta_tags %>
</head>
<body>
<div class="container">
<% flash.each do |key, value| %>
<div class="alert alert-<%= key %> alert-dismissible">
<button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">×</span></button>
<%= value %>
</div>
<% end %>
<%= yield %>
</div>
</body>
</html>
#Pavan #alexsmn I hope this helps?
config/environments/production.rb
Rails.application.configure do
# Settings specified here will take precedence over those in config/application.rb.
# Code is not reloaded between requests.
config.cache_classes = true
# Eager load code on boot. This eager loads most of Rails and
# your application in memory, allowing both threaded web servers
# and those relying on copy on write to perform better.
# Rake tasks automatically ignore this option for performance.
config.eager_load = true
# Full error reports are disabled and caching is turned on.
config.consider_all_requests_local = false
config.action_controller.perform_caching = true
# Enable Rack::Cache to put a simple HTTP cache in front of your application
# Add `rack-cache` to your Gemfile before enabling this.
# For large-scale production use, consider using a caching reverse proxy like nginx, varnish or squid.
# config.action_dispatch.rack_cache = true
# Disable Rails's static asset server (Apache or nginx will already do this).
config.serve_static_assets = false
# Compress JavaScripts and CSS.
config.assets.js_compressor = :uglifier
# config.assets.css_compressor = :sass
# Do not fallback to assets pipeline if a precompiled asset is missed.
config.assets.compile = false
# Generate digests for assets URLs.
config.assets.digest = true
# Version of your assets, change this if you want to expire all your assets.
config.assets.version = '1.0'
# Specifies the header that your server uses for sending files.
# config.action_dispatch.x_sendfile_header = "X-Sendfile" # for apache
# config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for nginx
# Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies.
# config.force_ssl = true
# Set to :debug to see everything in the log.
config.log_level = :info
# Prepend all log lines with the following tags.
# config.log_tags = [ :subdomain, :uuid ]
# Use a different logger for distributed setups.
# config.logger = ActiveSupport::TaggedLogging.new(SyslogLogger.new)
# Use a different cache store in production.
# config.cache_store = :mem_cache_store
# Enable serving of images, stylesheets, and JavaScripts from an asset server.
# config.action_controller.asset_host = "http://assets.example.com"
# Precompile additional assets.
# application.js, application.css, and all non-JS/CSS in app/assets folder are already added.
# config.assets.precompile += %w( search.js )
# Ignore bad email addresses and do not raise email delivery errors.
# Set this to true and configure the email server for immediate delivery to raise delivery errors.
# config.action_mailer.raise_delivery_errors = false
# Enable locale fallbacks for I18n (makes lookups for any locale fall back to
# the I18n.default_locale when a translation cannot be found).
config.i18n.fallbacks = true
# Send deprecation notices to registered listeners.
config.active_support.deprecation = :notify
# Disable automatic flushing of the log to improve performance.
# config.autoflush_log = false
# Use default logging formatter so that PID and timestamp are not suppressed.
config.log_formatter = ::Logger::Formatter.new
# Do not dump schema after migrations.
config.active_record.dump_schema_after_migration = false
end
config/environment.rb
# Load the Rails application.
require File.expand_path('../application', __FILE__)
# Initialize the Rails application.
Rails.application.initialize!
ActionMailer::Base.smtp_settings = {
:address => 'smtp.sendgrid.net',
:port => '587',
:authentication => :plain,
:user_name => ENV['SENDGRID_USERNAME'],
:password => ENV['SENDGRID_PASSWORD'],
:domain => 'heroku.com',
:enable_startstls_auto => true
}
I have had the same problem working with my current project. Actually, as I found out, this is a Gmail authentication problem. Your app is trying to login into Gmail account and cannot do it because Gmail does not see or recognize encrypted email and password. I temporarily solved this problem by writing necessary values into my smtp_settings directly, like:
smtp_settings = {
...
:user_name => "...your gmail email...",
:password => "...your gmail password...",
...
}
Also, I changed Gmail account security settings: turned off double authentication and allowed my account to be accessed by less secure apps. So, currently the app is deployed on Heroku and working. However, from cyber security point of view my solution is rather dangerous, so I am still looking for better ones.
EDITED!!!
There is a better way to encrypt gmail account settings. In my .bashrc file (is hidden in computer root directory - press Ctrl+H to reveal) I wrote the following lines of code:
export GMAIL_NAME=necessary value here
export GMAIL_PASSWORD=necessary value here
After this I also changed my smtp_settings one more time, like:
smtp_settings = {
...
user_name: ENV['GMAIL_NAME'],
password: ENV['GMAIL_PASSWORD'],
...
}
Finally, I configured repo setting on Heroku: Heroku/Personal apps/myApp/Settings, section "Config variables" via adding two new variables GMAIL_NAME and GMAIL_PASSWORD with necessary values.
It worked.
Try setting the following in your production.rb file:
config.action_mailer.delivery_method = :smtp
config.action_mailer.perform_deliveries = true
config.action_mailer.default_url_options = { host: 'nameless-taiga-1654.herokuapp.com' }
Also, to verify the configuration is correct, you can run heroku config.
Related
I am using StimulusJS + Stimulus Reflex and it's all working on development. When I deploy to production (Digital Ocean) the connected() method is not fired.
The ReflexClass is performed and the ActiveRecord is updated on the server-side but the JS controller is not fired. this.stimulate() it's successfully fired because I can see the page is refreshed with new data.
Can you help me? I don't know where to look at.
I am using Cloudflare, Devise if it matters.
import { Controller } from 'stimulus'
import StimulusReflex from 'stimulus_reflex'
export default class extends Controller {
connect () {
StimulusReflex.register(this)
console.log("THIS IS CALLED ONLY ON DEVELOPMENT ENV")
}
}
view.html
<div data-controller="item-group" data-id="<%=item_group.id%>" >
<%= form.check_box :state,{id: "state-#{item_group.id}",
data: {reflex: 'change->ItemGroup#state', "reflex-dataset": 'combined'}}, 'enabled', 'paused' %>
</div>
head.html
<%= csrf_meta_tags %>
<%= csp_meta_tag %>
<%= action_cable_meta_tag %>
config/enviroment/production.rb
Rails.application.configure do
# Settings specified here will take precedence over those in config/application.rb.
# Code is not reloaded between requests.
config.cache_classes = true
# Eager load code on boot. This eager loads most of Rails and
# your application in memory, allowing both threaded web servers
# and those relying on copy on write to perform better.
# Rake tasks automatically ignore this option for performance.
config.eager_load = true
# Full error reports are disabled and caching is turned on.
config.consider_all_requests_local = false
config.action_controller.perform_caching = true
# Ensures that a master key has been made available in either ENV["RAILS_MASTER_KEY"]
# or in config/master.key. This key is used to decrypt credentials (and other encrypted files).
config.require_master_key = true
# Disable serving static files from the `/public` folder by default since
# Apache or NGINX already handles this.
config.public_file_server.enabled = true
# Compress JavaScripts and CSS.
config.assets.js_compressor = Uglifier.new(harmony: true)
config.assets.css_compressor = :sass #
# Do not fallback to assets pipeline if a precompiled asset is missed.
config.assets.compile = false
# `config.assets.precompile` and `config.assets.version` have moved to config/initializers/assets.rb
# Enable serving of images, stylesheets, and JavaScripts from an asset server.
# config.action_controller.asset_host = 'http://assets.example.com'
# Specifies the header that your server uses for sending files.
# config.action_dispatch.x_sendfile_header = 'X-Sendfile' # for Apache
# config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for NGINX
# Store uploaded files on the local file system (see config/storage.yml for options)
config.active_storage.service = :amazon
# Mount Action Cable outside main process or domain
# config.action_cable.mount_path = nil
# config.action_cable.url = 'wss://example.com/cable'
# config.action_cable.allowed_request_origins = [ 'http://example.com', /http:\/\/example.*/ ]
# Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies.
config.force_ssl = false
# Use the lowest log level to ensure availability of diagnostic information
# when problems arise.
config.log_level = :debug
# Prepend all log lines with the following tags.
config.log_tags = [ :request_id ]
# Use a different cache store in production.
#config.cache_store = :redis_cache_store, { url: ENV['REDIS_URL'] }
config.cache_store = :redis_cache_store, {driver: :hiredis, url: ENV.fetch("REDIS_URL") { "redis://localhost:6379/1" }}
config.session_store :cache_store,
key: "_session",
compress: true,
pool_size: 5,
expire_after: 1.year
# Use a real queuing backend for Active Job (and separate queues per environment)
#config.active_job.queue_adapter = :resque
#config.active_job.queue_name_prefix = "amazon_#{Rails.env}"
config.action_mailer.perform_caching = false
config.action_mailer.default_url_options = { host: 'example.com', :protocol => 'https', locale: 'en'}
config.action_controller.default_url_options = { host: 'example.com', :protocol => 'https', locale: 'en'}
config.action_mailer.asset_host = 'https://www.example.com'
# Ignore bad email addresses and do not raise email delivery errors.
# Set this to true and configure the email server for immediate delivery to raise delivery errors.
# config.action_mailer.raise_delivery_errors = false
# Enable locale fallbacks for I18n (makes lookups for any locale fall back to
# the I18n.default_locale when a translation cannot be found).
config.i18n.fallbacks = true
# Send deprecation notices to registered listeners.
config.active_support.deprecation = :notify
# Use default logging formatter so that PID and timestamp are not suppressed.
config.log_formatter = ::Logger::Formatter.new
# Use a different logger for distributed setups.
# require 'syslog/logger'
# config.logger = ActiveSupport::TaggedLogging.new(Syslog::Logger.new 'app-name')
if ENV["RAILS_LOG_TO_STDOUT"].present?
logger = ActiveSupport::Logger.new(STDOUT)
logger.formatter = config.log_formatter
config.logger = ActiveSupport::TaggedLogging.new(logger)
end
# Do not dump schema after migrations.
config.active_record.dump_schema_after_migration = false
# Usato per Callback Advertisin Token (Url in model)
Rails.application.routes.default_url_options = config.action_mailer.default_url_options
end
config/cable.yml
development:
adapter: redis
url: <%= ENV.fetch("REDIS_URL") { "redis://localhost:6379/1" } %>
channel_prefix: development
test:
adapter: async
production:
adapter: redis
url: <%= ENV.fetch("REDIS_URL") { "redis://localhost:6379/1" } %>
channel_prefix: production
app/channels/application_cable/connection.rb
module ApplicationCable
class Connection < ActionCable::Connection::Base
identified_by :session_id
def connect
self.session_id = cookies.encrypted[:session_id]
end
end
end
NGNIX (managed by Coud66)
{% if passenger_action_cable %}
location /cable {
passenger_app_group_name {{ app_name }}_action_cable;
passenger_force_max_concurrent_requests_per_process 0;
}
{% endif %}
There have been many questions over many years where people have this issue. I have tried a combination of answers but I still can't get my updated stylesheet and javascript in my Rails 5.1.6 application to load in Heroku. It works on my local machine.
Here are my files.
app/assets/stylesheets/application.scss
*= require_tree .
*= require_self
app/views/layouts/application.html.erb
<html>
<head>
......
<%= stylesheet_link_tag "application", media: "all" %>
<%= csrf_meta_tags %>
<%= favicon_link_tag "/favicon.ico" %>
<%= render 'layouts/shim' %>
</head>
<body>
......
<%= debug(params) if Rails.env.development? %>
<%= javascript_include_tag "application" %>
</body>
</html>
config/application.rb
require_relative 'boot'
require 'rails/all'
# Require the gems listed in Gemfile, including any gems
# you've limited to :test, :development, or :production.
Bundler.require(*Rails.groups)
module EzklwRor
class Application < Rails::Application
# Initialize configuration defaults for originally generated Rails version.
config.load_defaults 5.1
# Settings in config/environments/* take precedence over those specified here.
# Application configuration should go into files in config/initializers
# -- all .rb files in that directory are automatically loaded.
RouteTranslator.config do |config|
config.generate_unnamed_unlocalized_routes = true
config.locale_param_key = :locale
end
config.exceptions_app = self.routes
config.action_dispatch.default_headers = { 'X-Frame-Options' => 'ALLOWALL' }
end
end
config/environments/production.rb
Rails.application.configure do
# Settings specified here will take precedence over those in config/application.rb.
# Code is not reloaded between requests.
config.cache_classes = true
# Eager load code on boot. This eager loads most of Rails and
# your application in memory, allowing both threaded web servers
# and those relying on copy on write to perform better.
# Rake tasks automatically ignore this option for performance.
config.eager_load = true
# Full error reports are disabled and caching is turned on.
config.consider_all_requests_local = false
config.action_controller.perform_caching = true
# We are using Rails ActionMailers in this application
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
domain: 'www.mydomain.com',
address: ENV["SMTPADDRESS"],
port: 587,
user_name: ENV["SMTPUSERNAME"],
password: ENV["SMTPPASSWORD"],
authentication: 'plain' }
config.action_mailer.perform_deliveries = true
config.action_mailer.raise_delivery_errors = true
# Attempt to read encrypted secrets from `config/secrets.yml.enc`.
# Requires an encryption key in `ENV["RAILS_MASTER_KEY"]` or
# `config/secrets.yml.key`.
config.read_encrypted_secrets = true
# Disable serving static files from the `/public` folder by default since
# Apache or NGINX already handles this.
config.public_file_server.enabled = ENV['RAILS_SERVE_STATIC_FILES'].present?
# Compress JavaScripts and CSS.
config.assets.js_compressor = :uglifier
# config.assets.css_compressor = :sass
# Do not fallback to assets pipeline if a precompiled asset is missed.
config.serve_static_assets = true
config.assets.compile = true
config.assets.digest = true
# `config.assets.precompile` and `config.assets.version` have moved to config/initializers/assets.rb
# Enable serving of images, stylesheets, and JavaScripts from an asset server.
# config.action_controller.asset_host = 'http://assets.example.com'
# Specifies the header that your server uses for sending files.
# config.action_dispatch.x_sendfile_header = 'X-Sendfile' # for Apache
# config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for NGINX
# Mount Action Cable outside main process or domain
# config.action_cable.mount_path = nil
# config.action_cable.url = 'wss://example.com/cable'
# config.action_cable.allowed_request_origins = [ 'http://example.com', /http:\/\/example.*/ ]
# Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies.
config.force_ssl = true
# Use the lowest log level to ensure availability of diagnostic information
# when problems arise.
config.log_level = :debug
# Prepend all log lines with the following tags.
config.log_tags = [ :request_id ]
# Use a different cache store in production.
# config.cache_store = :mem_cache_store
# Use a real queuing backend for Active Job (and separate queues per environment)
# config.active_job.queue_adapter = :resque
# config.active_job.queue_name_prefix = "ezklw_#{Rails.env}"
config.action_mailer.perform_caching = false
# Ignore bad email addresses and do not raise email delivery errors.
# Set this to true and configure the email server for immediate delivery to raise delivery errors.
# config.action_mailer.raise_delivery_errors = false
# Enable locale fallbacks for I18n (makes lookups for any locale fall back to
# the I18n.default_locale when a translation cannot be found).
config.i18n.fallbacks = [I18n.default_locale]
# Send deprecation notices to registered listeners.
config.active_support.deprecation = :notify
# Use default logging formatter so that PID and timestamp are not suppressed.
config.log_formatter = ::Logger::Formatter.new
# Use a different logger for distributed setups.
# require 'syslog/logger'
# config.logger = ActiveSupport::TaggedLogging.new(Syslog::Logger.new 'app-name')
if ENV["RAILS_LOG_TO_STDOUT"].present?
logger = ActiveSupport::Logger.new(STDOUT)
logger.formatter = config.log_formatter
config.logger = ActiveSupport::TaggedLogging.new(logger)
end
# Do not dump schema after migrations.
config.active_record.dump_schema_after_migration = false
end
Here is what I have done on my local machine.
rake assets:clean
rake assets:precompile
rake assets:precompile RAILS_ENV=production
committed changes with public/assets folder included using Github desktop app
git push heroku master
git push heroku master -f when initial change did not work after adding spaces to a file to avoid everything-up-to-date message.
heroku rake assets:precompile RAILS_ENV=production
heroku restart several times along the way
heroku repo:clone -a myapp to verify that my app/assets folder was up to date
heroku repo:reset -a myapp to empty the heroku repo
git push heroku master
heroku logs -t
I have cleared the cache in my browser several times, rebooted my computer and displayed the new app on different devices. I see no errors in the heroku log. My css and js are not working. Where else can I look to fix this?
I checked your configuration files, and in the config/environments/production.rb you have a mistake with config.serve_static_assets = true; therefore, you needed to change to config.public_file_server.enabled = true, and also, please change config.assets.compile = false because I don't think that you want to compile assets with every single request.
Here is similar usage: config/environments/production.rb
For more information please check the same Q&A: https://stackoverflow.com/a/54376240/8929392
So I'm doing an online bootcamp on codermanual, btw I'm a total beginner and just started learning Ruby and the rest of webdev stuff.
I'm stuck on a certain step and I'm having an issue regarding "receiving emails" from the contact forms page of my webapp via heroku.
For some reason, I can't seem to make sendgrid work.
When I hit submit button of my contact form, webpage returns an error message.
I followed the steps precisely but there seems to be a problem with my contacts_controller.rb particularly this line of code:
ContactMailer.contact_email(name, email, body).deliver
ruby v2.3.0p0
$heroku logs
ArgumentError (An SMTP To address is required to send a message. Set the message smtp_envelope_to, to, cc, or bcc address.):
2016-06-13T05:24:00.381485+00:00 app[web.1]: app/controllers/contacts_controller.rb:14:in `create'
Appreciate the help.
Here are the rest of the files:
controllers/contacts_controller.rb
class ContactsController < ApplicationController
def new
#contact = Contact.new
end
def create
#contact = Contact.new(contact_params)
if #contact.save
name = params[:contact][:name]
email = params[:contact][:email]
body = params[:contact][:comments]
ContactMailer.contact_email(name, email, body).deliver
flash[:success] = 'Message sent.'
redirect_to new_contact_path
else
flash[:danger] = 'Error occured, message has not been sent'
redirect_to new_contact_path
end
end
private
def contact_params
params.require(:contact).permit(:name, :email, :comments)
end
end
config/application.rb
require File.expand_path('../boot', __FILE__)
require 'rails/all'
# Require the gems listed in Gemfile, including any gems
# you've limited to :test, :development, or :production.
Bundler.require(*Rails.groups)
module SimplecodecastsSaas
class Application < Rails::Application
# Settings in config/environments/* take precedence over those specified here.
# Application configuration should go into files in config/initializers
# -- all .rb files in that directory are automatically loaded.
# Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
# Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC.
# config.time_zone = 'Central Time (US & Canada)'
# The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
# config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
# config.i18n.default_locale = :de
end
end
views/contact_mailer/contact_email.html.erb
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<p>You have received a message from the site's contact form, from <%= "#{ #name }, #{ #email }." %></p>
<p><%= #body %></p>
</body>
environments/production.rb
Rails.application.configure do
# Settings specified here will take precedence over those in config/application.rb.
# Code is not reloaded between requests.
config.cache_classes = true
# Eager load code on boot. This eager loads most of Rails and
# your application in memory, allowing both threaded web servers
# and those relying on copy on write to perform better.
# Rake tasks automatically ignore this option for performance.
config.eager_load = true
# Full error reports are disabled and caching is turned on.
config.consider_all_requests_local = false
config.action_controller.perform_caching = true
# Enable Rack::Cache to put a simple HTTP cache in front of your application
# Add `rack-cache` to your Gemfile before enabling this.
# For large-scale production use, consider using a caching reverse proxy like nginx, varnish or squid.
# config.action_dispatch.rack_cache = true
# Disable Rails's static asset server (Apache or nginx will already do this).
config.serve_static_assets = false
# Compress JavaScripts and CSS.
config.assets.js_compressor = :uglifier
# config.assets.css_compressor = :sass
# Do not fallback to assets pipeline if a precompiled asset is missed.
config.assets.compile = false
# Generate digests for assets URLs.
config.assets.digest = true
# Version of your assets, change this if you want to expire all your assets.
config.assets.version = '1.0'
# Specifies the header that your server uses for sending files.
# config.action_dispatch.x_sendfile_header = "X-Sendfile" # for apache
# config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for nginx
# Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies.
# config.force_ssl = true
# Set to :debug to see everything in the log.
config.log_level = :info
# Prepend all log lines with the following tags.
# config.log_tags = [ :subdomain, :uuid ]
# Use a different logger for distributed setups.
# config.logger = ActiveSupport::TaggedLogging.new(SyslogLogger.new)
# Use a different cache store in production.
# config.cache_store = :mem_cache_store
# Enable serving of images, stylesheets, and JavaScripts from an asset server.
# config.action_controller.asset_host = "http://assets.example.com"
# Precompile additional assets.
# application.js, application.css, and all non-JS/CSS in app/assets folder are already added.
# config.assets.precompile += %w( search.js )
# Ignore bad email addresses and do not raise email delivery errors.
# Set this to true and configure the email server for immediate delivery to raise delivery errors.
# config.action_mailer.raise_delivery_errors = false
# Enable locale fallbacks for I18n (makes lookups for any locale fall back to
# the I18n.default_locale when a translation cannot be found).
config.i18n.fallbacks = true
# Send deprecation notices to registered listeners.
config.active_support.deprecation = :notify
# Disable automatic flushing of the log to improve performance.
# config.autoflush_log = false
# Use default logging formatter so that PID and timestamp are not suppressed.
config.log_formatter = ::Logger::Formatter.new
# Do not dump schema after migrations.
config.active_record.dump_schema_after_migration = false
end
environments/development.rb
Rails.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 web server when you make code changes.
config.cache_classes = false
#a fix for circular dependency while autoloading constant.
#config.middleware.delete Rack::Lock
# Do not eager load code on boot.
config.eager_load = false
# Show full error reports and disable caching.
config.consider_all_requests_local = true
config.action_controller.perform_caching = false
# Don't care if the mailer can't send.
config.action_mailer.raise_delivery_errors = false
# Print deprecation notices to the Rails logger.
config.active_support.deprecation = :log
# Raise an error on page load if there are pending migrations.
config.active_record.migration_error = :page_load
# Debug mode disables concatenation and preprocessing of assets.
# This option may cause significant delays in view rendering with a large
# number of complex assets.
config.assets.debug = true
# Adds additional error checking when serving assets at runtime.
# Checks for improperly declared sprockets dependencies.
# Raises helpful error messages.
config.assets.raise_runtime_errors = true
# Raises error for missing translations
# config.action_view.raise_on_missing_translations = true
end
apps/mailers/contact_mailer.rb
class ContactMailer < ActionMailer::Base
default to: "jxxmxlmxo#gmail.com"
def contact_email(name, email, body)
#name = name
#email = email
#body = body
mail(from: email, subject: 'Contact Form Message')
end
end
I am trying to send notification mail using Action mailer in rails 4 but it is not working properly. After solving many error I am able to send the mail and no error shows in the console but the mail is not received. This has always worked for me before but I dont know how it is not happening now. Here is my output in the console.
AdminMailer#subscription_added: processed outbound mail in 202.7ms
Sent mail to receiver#gmail.com (9.8ms)
Date: Sat, 28 Nov 2015 21:25:52 +0530
To: receiver#gmail.com
Message-ID: <5659ce8829e54_2b0563310f2520dc#ubuntu.mail>
Subject: Subscription addded
Mime-Version: 1.0
Content-Type: text/html;
charset=UTF-8
Content-Transfer-Encoding: 7bit
<!--XRAY START 8 /home/yogesh/Desktop/new/munam/app/views/layouts/mailer.html.haml-->
<hmtl>
<body>
<!--XRAY START 7 /home/yogesh/Desktop/new/munam/app/views/admin_mailer/subscription_added.html.haml-->
name of receiver
Email receiver#gmail.com
<!--XRAY END 7-->
</body>
</hmtl>
<!--XRAY END 8-->
Completed 302 Found in 320ms (ActiveRecord: 70.3ms)
Here is my code for it
In my development.rb
Rails.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 web server when you make code changes.
config.cache_classes = false
# Do not eager load code on boot.
config.eager_load = false
# Show full error reports and disable caching.
config.consider_all_requests_local = true
config.action_controller.perform_caching = false
# Don't care if the mailer can't send.
config.action_mailer.raise_delivery_errors = false
# Print deprecation notices to the Rails logger.
config.active_support.deprecation = :log
# Raise an error on page load if there are pending migrations.
config.active_record.migration_error = :page_load
# Debug mode disables concatenation and preprocessing of assets.
# This option may cause significant delays in view rendering with a large
# number of complex assets.
config.assets.debug = true
# Adds additional error checking when serving assets at runtime.
# Checks for improperly declared sprockets dependencies.
# Raises helpful error messages.
config.assets.raise_runtime_errors = true
# Raises error for missing translations
# config.action_view.raise_on_missing_translations = true
config.action_mailer.default_url_options = { :host => "localhost:3000" }
# Automatically inject JavaScript needed for LiveReload
# config.middleware.insert_after(ActionDispatch::Static, Rack::LiveReload)
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
address: 'smtp.gmail.com',
port: 587,
domain: 'localhost:3000',
user_name: 'mymail#gmail.com',
password: 'mypassword',
authentication: 'plain',
enable_starttls_auto: true }
end
My code that triggers the mail
AdminMailer.subscription_added(#subscription).deliver_now
My Admin mailer
class AdminMailer < ApplicationMailer
def subscription_added(subscription)
#subscription = subscription
begin
mail(:to => "sender#gmail.com", :subject => "Subscription addded")
rescue Exception => e
end
end
end
I will really thankful if someone tells me where I am going wrong or what extra do I need to do. Thanks a lot in advance.
You're hiding any errors that may occur when trying to send the email, with this line:
config.action_mailer.raise_delivery_errors = false
Change it to true, restart your server, and you will get an error if you try to send mail and it fails.
In development, I'd recommend against using a real live mail server, though - I'd recommend using something like Mailcatcher (http://mailcatcher.me/)
Try to raise run-time errors using the following code in development.rb file.
config.action_mailer.perform_deliveries = true
config.action_mailer.raise_delivery_errors = true
I'm creating an app using Ruby On Rails and Devise. I've created a User model and an Admin model and I have the app working fine when I run it locally but when I run it on heroku I'm having problems. The trouble is when I try to create a new admin I'm shown an error message that says "We're sorry, but something went wrong." I've already done a rake db:migrate and heroku run rake db:migrate. When I check heroku logs I see this:
2013-04-08T19:34:49+00:00 app[web.1]: Started GET "/admins/sign_up" for 98.154.183.5 at 2013-04-08 19:34:49 +0000
2013-04-08T19:34:49+00:00 app[web.1]: Processing by Admins::RegistrationsController#new as HTML
2013-04-08T19:34:50+00:00 app[web.1]: Rendered devise/registrations/new.html.erb within layouts/application (431.3ms)
2013-04-08T19:34:50+00:00 app[web.1]: ActionView::Template::Error (undefined method `name' for #<Admin:0x00000005207678>):
2013-04-08T19:34:50+00:00 app[web.1]: Completed 500 Internal Server Error in 549ms
2013-04-08T19:34:50+00:00 app[web.1]:
2013-04-08T19:34:50+00:00 app[web.1]: 3: <%= simple_form_for(resource, :as => resource_name, :url => registration_path(resource_name), :html => { class: 'form-horizontal'}) do |f| %>
2013-04-08T19:34:50+00:00 app[web.1]: 4: <%= f.error_notification %>
2013-04-08T19:34:50+00:00 app[web.1]: 5:
2013-04-08T19:34:50+00:00 app[web.1]: 6: <%= f.input :name %>
2013-04-08T19:34:50+00:00 app[web.1]: 8: <%= f.input :password %>
2013-04-08T19:34:50+00:00 app[web.1]: app/views/devise/registrations/new.html.erb:6:in `block in _app_views_devise_registrations_new_html_erb___3397140481100313441_30072880'
2013-04-08T19:34:50+00:00 app[web.1]: app/views/devise/registrations/new.html.erb:3:in `_app_views_devise_registrations_new_html_erb___3397140481100313441_30072880'
2013-04-08T19:34:50+00:00 app[web.1]: 7: <%= f.input :email %>
2013-04-08T19:34:50+00:00 app[web.1]: 9: <%= f.input :password_confirmation %>
2013-04-08T19:34:50+00:00 app[web.1]:
2013-04-08T19:34:50+00:00 app[web.1]:
2013-04-08T19:34:50+00:00 heroku[router]: at=info method=GET path=/admins/sign_up host=protected-cliffs-2228.herokuapp.com fwd="98.154.183.5" dyno=web.1 connect=1ms service=559ms status=500 bytes=643
For some reason unknown to me heroku is not linking to admins/registrations/new.html.erb but instead it's linking to devise/registrations/new.html.erb where it's reading the 'name' attribute that is showing up as an undefined method error.
My controllers/admins/registrations_controller.rb file looks like this:
class Admins::RegistrationsController < Devise::RegistrationsController
end
My routes.rb file looks like this:
MyFirstApp::Application.routes.draw do
get "users/show"
devise_for :admins, :controllers => { :registrations => "admins/registrations", :sessions => "admins/sessions" } do
get "/admins/sign_up" => "admins/registrations#new"
get "/admins/sign_in" => "admins/sessions#new"
end
resources :posts
devise_for :users
match 'users/:id' => 'users#show'
root :to => 'pages#home'
get 'about' => 'pages#about'
end
My development.rb file
MyFirstApp::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 web server when you make code changes.
config.cache_classes = false
# Log error messages when you accidentally call methods on nil.
config.whiny_nils = true
# Show full error reports and disable caching
config.consider_all_requests_local = true
config.action_controller.perform_caching = false
# Don't care if the mailer can't send
config.action_mailer.raise_delivery_errors = false
# 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
# Raise exception on mass assignment protection for Active Record models
config.active_record.mass_assignment_sanitizer = :strict
# Log the query plan for queries taking more than this (works
# with SQLite, MySQL, and PostgreSQL)
config.active_record.auto_explain_threshold_in_seconds = 0.5
# Do not compress assets
config.assets.compress = false
# Expands the lines which load the assets
config.assets.debug = true
config.action_mailer.default_url_options = { :host => 'localhost:3000' }
end
My production.rb file
MyFirstApp::Application.configure do
# Settings specified here will take precedence over those in config/application.rb
# Code is not reloaded between requests
config.cache_classes = true
# Full error reports are disabled and caching is turned on
config.consider_all_requests_local = false
config.action_controller.perform_caching = true
# Disable Rails's static asset server (Apache or nginx will already do this)
config.serve_static_assets = false
# Compress JavaScripts and CSS
config.assets.compress = true
# Don't fallback to assets pipeline if a precompiled asset is missed
config.assets.compile = false
# Generate digests for assets URLs
config.assets.digest = true
# Defaults to nil and saved in location specified by config.assets.prefix
# config.assets.manifest = YOUR_PATH
# Specifies the header that your server uses for sending files
# config.action_dispatch.x_sendfile_header = "X-Sendfile" # for apache
# config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for nginx
# Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies.
# config.force_ssl = true
# See everything in the log (default is :info)
# config.log_level = :debug
# Prepend all log lines with the following tags
# config.log_tags = [ :subdomain, :uuid ]
# Use a different logger for distributed setups
# config.logger = ActiveSupport::TaggedLogging.new(SyslogLogger.new)
# Use a different cache store in production
# config.cache_store = :mem_cache_store
# Enable serving of images, stylesheets, and JavaScripts from an asset server
# config.action_controller.asset_host = "http://assets.example.com"
# Precompile additional assets (application.js, application.css, and all non-JS/CSS are already added)
# config.assets.precompile += %w( search.js )
# Disable delivery errors, bad email addresses will be ignored
# config.action_mailer.raise_delivery_errors = false
# Enable threaded mode
# config.threadsafe!
# Enable locale fallbacks for I18n (makes lookups for any locale fall back to
# the I18n.default_locale when a translation can not be found)
config.i18n.fallbacks = true
# Send deprecation notices to registered listeners
config.active_support.deprecation = :notify
# Log the query plan for queries taking more than this (works
# with SQLite, MySQL, and PostgreSQL)
# config.active_record.auto_explain_threshold_in_seconds = 0.5
#In production, :host should be set to the actual host of your application.
config.action_mailer.default_url_options = { :host => 'myfirstapp.heroku.com' }
#Configuring Amazon S3 for Paperclip file uploads
config.paperclip_defaults = {
:storage => :s3,
:s3_credentials => {
:bucket => ENV['AWS_BUCKET'],
:access_key_id => ENV['AWS_ACCESS_KEY_ID'],
:secret_access_key => ENV['AWS_SECRET_ACCESS_KEY']
}
}
end
My .gitignore file
# See http://help.github.com/ignore-files/ for more about ignoring files.
#
# If you find yourself ignoring temporary files generated by your text editor
# or operating system, you probably want to add a global ignore instead:
# git config --global core.excludesfile ~/.gitignore_global
# Ignore bundler config
/.bundle
# Ignore the default SQLite database.
/db/*.sqlite3
# Ignore all logfiles and tempfiles.
/log/*.log
/tmp
doc/
*.swp
*~
.project
.DS_Store
.idea
# Ignore Paperclip unloaded files
/public/system
I'd appreciate any help I can get! This is my first time creating an app so I apologize if my question is dumb but I'm stuck and I need some help!
First check your gitrepo to make sure the file, or a related file, for some reason has been ignored.
And if that isn't the issue then just nuke the heroku project and start over.
Heroku has a special way of sometimes not creating new repos/projects correctly. The fail rate is pretty small, but you might have just rolled snake eyes.
If that doesn't work then post your production.rb and development.rb.