2013-06-23 9 views
0

Я только что запустил приложение для рельсов с героку (http://fast-reaches-9399.herokuapp.com/). Я хочу, чтобы люди могли набирать текст в текстовом поле вверху, а затем нажмите кнопку «Отправить», а затем напишите мне, что находится в текстовом поле. У меня действительно есть проблемы с этим, хотя. Он перенаправляет в среду разработки, но, похоже, не отправляет электронное письмо. И я получаю 500 ошибок в производстве. Вот некоторые соответствующий код ...проблема с электронной почтой одним щелчком мыши

application_controller.rb

class ApplicationController < ActionController::Base 
    protect_from_forgery 

    def email 
    UserMailer.idea_bar(params[:message]).deliver 
    redirect_to "/" # how can I redirect to the page the user was just on? 
    end 
end 

/mailers/user_mailer.rb

class UserMailer < ActionMailer::Base 
    default from: "[email protected]", to: "[email protected]", subject: "collegeanswers" 

    def idea_bar(message) 
    mail(:body => message) 
    end 
end 

application.html.erb (расположение файла)

<div class="idea_bar"> 
    <div class="left_idea_bar"> 
     <p>Ideas, comments, questions, suggestions? Help us help you!</p> 
     <%= form_tag("/application_controller/email", :method => "post", :id => "idea_bar_form") do %> 
      <%= text_area_tag('message', nil, :size => "60x4", :id => "message", :name => "message") %> <br /> 
      <%= label_tag(:email, "• include your email if you want a response:") %> 
      <%= text_field_tag(:email, nil, :id => "email", :size => "36") %> 
    </div> 
      <button id="submit" type="submit" form="idea_bar_form"><span id="big_submit">Send</span> 
      <span id="small_submit"><br />&#8226 one click<br />&#8226 anonymous</span></button> 
     <% end %> 
</div> 

/user_mailer/idea_bar.html.erb (тестовый файл. Я хочу, чтобы письмо было тем, что находится в текстовом поле, а не этим)

<html> 
    <head></head> 
    <body> 
     <p>hello</p> 
    </body> 
</html> 

/user_mailer/idea_bar.text.erb

hello 

журналы

~/collegeanswerz >> heroku logs -n 100 
2013-06-24T02:10:39.511211+00:00 app[web.1]: [2013-06-24 02:10:39] INFO WEBrick::HTTPServer#start: pid=2 port=37425 
2013-06-24T02:10:39.628181+00:00 heroku[web.1]: State changed from starting to up 
2013-06-24T02:10:39.971477+00:00 heroku[web.1]: Stopping all processes with SIGTERM 
2013-06-24T02:10:41.046475+00:00 app[web.1]: [2013-06-24 02:10:41] ERROR SignalException: SIGTERM 
2013-06-24T02:10:41.046475+00:00 app[web.1]: /app/vendor/ruby-1.9.3/lib/ruby/1.9.1/webrick/server.rb:98:in `select' 
2013-06-24T02:10:46.399057+00:00 app[web.1]: Started GET "/" for 150.212.18.15 at 2013-06-24 02:10:46 +0000 
2013-06-24T02:10:46.588166+00:00 heroku[router]: at=info method=GET path=/ host=fast-reaches-9399.herokuapp.com fwd="150.212.18.15" dyno=web.1 connect=1ms service=198ms status=200 bytes=14988 
2013-06-24T02:10:46.547918+00:00 app[web.1]: Processing by StaticPagesController#home as HTML 
2013-06-24T02:10:46.581761+00:00 app[web.1]: Rendered static_pages/home.html.erb within layouts/application (3.8ms) 
2013-06-24T02:10:46.584211+00:00 app[web.1]: Completed 200 OK in 36ms (Views: 35.8ms | ActiveRecord: 0.0ms) 
2013-06-24T02:10:46.827096+00:00 heroku[router]: at=info method=GET path=/assets/home-73d942132cfdcc305dabf385494f8201.css host=fast-reaches-9399.herokuapp.com fwd="150.212.18.15" dyno=web.1 connect=1ms service=6ms status=200 bytes=1884 
2013-06-24T02:10:46.814074+00:00 heroku[router]: at=info method=GET path=/assets/layout-eae006a3ffc93619e067580f95bb8a9a.css host=fast-reaches-9399.herokuapp.com fwd="150.212.18.15" dyno=web.1 connect=3ms service=10ms status=200 bytes=1643 
2013-06-24T02:10:46.834802+00:00 heroku[router]: at=info method=GET path=/assets/application-e432bc54db845c729a762e0d298d3579.js host=fast-reaches-9399.herokuapp.com fwd="150.212.18.15" dyno=web.1 connect=2ms service=15ms status=200 bytes=156605 
2013-06-24T02:10:47.262693+00:00 heroku[router]: at=info method=GET path=/favicon.ico host=fast-reaches-9399.herokuapp.com fwd="150.212.18.15" dyno=web.1 connect=4ms service=6ms status=200 bytes=0 
2013-06-24T02:10:49.760439+00:00 heroku[web.1]: Stopping remaining processes with SIGKILL 
2013-06-24T02:10:49.760205+00:00 heroku[web.1]: Error R12 (Exit timeout) -> At least one process failed to exit within 10 seconds of SIGTERM 
2013-06-24T02:10:52.386481+00:00 heroku[web.1]: Process exited with status 137 
2013-06-24T02:15:55.505285+00:00 app[web.1]: Started GET "/" for 67.171.66.44 at 2013-06-24 02:15:55 +0000 
2013-06-24T02:15:55.510268+00:00 app[web.1]: Processing by StaticPagesController#home as HTML 
2013-06-24T02:15:55.512568+00:00 app[web.1]: Rendered static_pages/home.html.erb within layouts/application (1.6ms) 
2013-06-24T02:15:55.514297+00:00 app[web.1]: Completed 200 OK in 4ms (Views: 3.7ms | ActiveRecord: 0.0ms) 
2013-06-24T02:15:55.518380+00:00 heroku[router]: at=info method=GET path=/ host=fast-reaches-9399.herokuapp.com fwd="67.171.66.44" dyno=web.1 connect=7ms service=23ms status=200 bytes=14988 
2013-06-24T02:15:55.739788+00:00 heroku[router]: at=info method=GET path=/assets/layout-eae006a3ffc93619e067580f95bb8a9a.css host=fast-reaches-9399.herokuapp.com fwd="67.171.66.44" dyno=web.1 connect=3ms service=6ms status=200 bytes=1643 
2013-06-24T02:15:55.786186+00:00 heroku[router]: at=info method=GET path=/assets/home-73d942132cfdcc305dabf385494f8201.css host=fast-reaches-9399.herokuapp.com fwd="67.171.66.44" dyno=web.1 connect=2ms service=5ms status=200 bytes=1884 
2013-06-24T02:15:55.854372+00:00 heroku[router]: at=info method=GET path=/assets/application-e432bc54db845c729a762e0d298d3579.js host=fast-reaches-9399.herokuapp.com fwd="67.171.66.44" dyno=web.1 connect=3ms service=26ms status=200 bytes=156605 
2013-06-24T02:19:33.509774+00:00 app[web.1]: Started GET "/colleges" for 150.212.18.15 at 2013-06-24 02:19:33 +0000 
2013-06-24T02:19:33.513257+00:00 app[web.1]: Processing by StaticPagesController#colleges as HTML 
2013-06-24T02:19:33.523421+00:00 heroku[router]: at=info method=GET path=/colleges host=fast-reaches-9399.herokuapp.com fwd="150.212.18.15" dyno=web.1 connect=2ms service=21ms status=304 bytes=0 
2013-06-24T02:19:33.524174+00:00 app[web.1]: Completed 200 OK in 11ms (Views: 10.4ms | ActiveRecord: 0.0ms) 
2013-06-24T02:19:33.522339+00:00 app[web.1]: Rendered static_pages/colleges.html.erb within layouts/application (7.7ms) 
2013-06-24T02:19:33.753391+00:00 heroku[router]: at=info method=GET path=/assets/application-e432bc54db845c729a762e0d298d3579.js host=fast-reaches-9399.herokuapp.com fwd="150.212.18.15" dyno=web.1 connect=2ms service=5ms status=304 bytes=0 
2013-06-24T02:19:33.735957+00:00 heroku[router]: at=info method=GET path=/assets/layout-eae006a3ffc93619e067580f95bb8a9a.css host=fast-reaches-9399.herokuapp.com fwd="150.212.18.15" dyno=web.1 connect=2ms service=6ms status=304 bytes=0 
2013-06-24T02:19:33.811360+00:00 heroku[router]: at=info method=GET path=/assets/colleges-7adcb0138796cf2dd39ad973ccd58699.css host=fast-reaches-9399.herokuapp.com fwd="150.212.18.15" dyno=web.1 connect=5ms service=6ms status=200 bytes=232 
2013-06-24T02:19:33.972423+00:00 heroku[router]: at=info method=GET path=/favicon.ico host=fast-reaches-9399.herokuapp.com fwd="150.212.18.15" dyno=web.1 connect=1ms service=6ms status=304 bytes=0 
2013-06-24T02:19:35.619992+00:00 app[web.1]: Started GET "/university-of-pittsburgh" for 150.212.18.15 at 2013-06-24 02:19:35 +0000 
2013-06-24T02:19:35.624209+00:00 app[web.1]: Parameters: {"college"=>"university-of-pittsburgh"} 
2013-06-24T02:19:35.624209+00:00 app[web.1]: Processing by CollegePagesController#college_page as HTML 
2013-06-24T02:19:35.876371+00:00 app[web.1]: Rendered college_pages/college_page.html.erb within layouts/application (20.9ms) 
2013-06-24T02:19:35.878070+00:00 app[web.1]: Completed 200 OK in 254ms (Views: 50.0ms | ActiveRecord: 22.2ms) 
2013-06-24T02:19:35.902402+00:00 heroku[router]: at=info method=GET path=/university-of-pittsburgh host=fast-reaches-9399.herokuapp.com fwd="150.212.18.15" dyno=web.1 connect=7ms service=289ms status=200 bytes=29578 
2013-06-24T02:19:35.993171+00:00 heroku[router]: at=info method=GET path=/assets/college_pages-72b79bbce46f6e1c4a7b947a635cb3ef.css host=fast-reaches-9399.herokuapp.com fwd="150.212.18.15" dyno=web.1 connect=2ms service=8ms status=200 bytes=4711 
2013-06-24T03:23:03.750562+00:00 heroku[web.1]: Idling 
2013-06-24T03:23:06.124578+00:00 heroku[web.1]: Stopping all processes with SIGTERM 
2013-06-24T03:23:06.590444+00:00 app[web.1]: /app/vendor/ruby-1.9.3/lib/ruby/1.9.1/webrick/server.rb:98:in `select' 
2013-06-24T03:23:06.590444+00:00 app[web.1]: [2013-06-24 03:23:06] ERROR SignalException: SIGTERM 
2013-06-24T03:23:15.819421+00:00 heroku[web.1]: Stopping remaining processes with SIGKILL 
2013-06-24T03:23:15.819273+00:00 heroku[web.1]: Error R12 (Exit timeout) -> At least one process failed to exit within 10 seconds of SIGTERM 
2013-06-24T03:23:17.542955+00:00 heroku[web.1]: Process exited with status 137 
2013-06-24T03:23:17.555718+00:00 heroku[web.1]: State changed from up to down 
2013-06-24T04:43:11.725754+00:00 heroku[web.1]: State changed from down to starting 
2013-06-24T04:43:11.725389+00:00 heroku[web.1]: Unidling 
2013-06-24T04:43:15.022448+00:00 heroku[web.1]: Starting process with command `bundle exec rails server -p 20121` 
2013-06-24T04:43:19.525120+00:00 app[web.1]: DEPRECATION WARNING: You have Rails 2.3-style plugins in vendor/plugins! Support for these plugins will be removed in Rails 4.0. Move them out and bundle them in your Gemfile, or fold them in to your app as lib/myplugin/* and config/initializers/myplugin.rb. See the release notes for more on this: http://weblog.rubyonrails.org/2012/1/4/rails-3-2-0-rc2-has-been-released. (called from <top (required)> at /app/config/environment.rb:5) 
2013-06-24T04:43:19.525120+00:00 app[web.1]: DEPRECATION WARNING: You have Rails 2.3-style plugins in vendor/plugins! Support for these plugins will be removed in Rails 4.0. Move them out and bundle them in your Gemfile, or fold them in to your app as lib/myplugin/* and config/initializers/myplugin.rb. See the release notes for more on this: http://weblog.rubyonrails.org/2012/1/4/rails-3-2-0-rc2-has-been-released. (called from <top (required)> at /app/config/environment.rb:5) 
2013-06-24T04:43:28.871809+00:00 app[web.1]: => Call with -d to detach 
2013-06-24T04:43:28.871809+00:00 app[web.1]: Connecting to database specified by DATABASE_URL 
2013-06-24T04:43:28.871809+00:00 app[web.1]: => Rails 3.2.13 application starting in production on http://0.0.0.0:20121 
2013-06-24T04:43:28.871809+00:00 app[web.1]: => Booting WEBrick 
2013-06-24T04:43:28.871809+00:00 app[web.1]: => Ctrl-C to shutdown server 
2013-06-24T04:43:29.530107+00:00 app[web.1]: [2013-06-24 04:43:29] INFO WEBrick 1.3.1 
2013-06-24T04:43:29.530107+00:00 app[web.1]: [2013-06-24 04:43:29] INFO ruby 1.9.3 (2013-05-15) [x86_64-linux] 
2013-06-24T04:43:29.530878+00:00 app[web.1]: [2013-06-24 04:43:29] INFO WEBrick::HTTPServer#start: pid=2 port=20121 
2013-06-24T04:43:30.022925+00:00 heroku[web.1]: State changed from starting to up 
2013-06-24T04:43:31.838145+00:00 app[web.1]: Started GET "/" for 150.212.13.47 at 2013-06-24 04:43:31 +0000 
2013-06-24T04:43:32.678465+00:00 app[web.1]: Processing by StaticPagesController#home as HTML 
2013-06-24T04:43:32.889354+00:00 app[web.1]: Rendered static_pages/home.html.erb within layouts/application (31.0ms) 
2013-06-24T04:43:32.932875+00:00 app[web.1]: Completed 200 OK in 254ms (Views: 246.6ms | ActiveRecord: 0.0ms) 
2013-06-24T04:43:32.949968+00:00 heroku[router]: at=info method=GET path=/ host=fast-reaches-9399.herokuapp.com fwd="150.212.13.47" dyno=web.1 connect=2ms service=1132ms status=304 bytes=0 
2013-06-24T04:43:53.901496+00:00 app[web.1]: Started GET "/" for 24.131.255.163 at 2013-06-24 04:43:53 +0000 
2013-06-24T04:43:53.905840+00:00 app[web.1]: Processing by StaticPagesController#home as HTML 
2013-06-24T04:43:53.918816+00:00 app[web.1]: Rendered static_pages/home.html.erb within layouts/application (1.1ms) 
2013-06-24T04:43:53.924969+00:00 app[web.1]: Completed 200 OK in 19ms (Views: 7.6ms | ActiveRecord: 0.0ms) 
2013-06-24T04:43:53.927908+00:00 heroku[router]: at=info method=GET path=/ host=fast-reaches-9399.herokuapp.com fwd="24.131.255.163" dyno=web.1 connect=1ms service=44ms status=200 bytes=14988 
2013-06-24T04:43:54.371502+00:00 heroku[router]: at=info method=GET path=/assets/layout-eae006a3ffc93619e067580f95bb8a9a.css host=fast-reaches-9399.herokuapp.com fwd="24.131.255.163" dyno=web.1 connect=4ms service=12ms status=304 bytes=0 
2013-06-24T04:43:54.400418+00:00 heroku[router]: at=info method=GET path=/assets/home-73d942132cfdcc305dabf385494f8201.css host=fast-reaches-9399.herokuapp.com fwd="24.131.255.163" dyno=web.1 connect=3ms service=27ms status=304 bytes=0 
2013-06-24T04:43:54.404305+00:00 heroku[router]: at=info method=GET path=/assets/application-e432bc54db845c729a762e0d298d3579.js host=fast-reaches-9399.herokuapp.com fwd="24.131.255.163" dyno=web.1 connect=1ms service=18ms status=304 bytes=0 
2013-06-24T04:43:54.987065+00:00 heroku[router]: at=info method=GET path=/favicon.ico host=fast-reaches-9399.herokuapp.com fwd="24.131.255.163" dyno=web.1 connect=2ms service=6ms status=304 bytes=0 
2013-06-24T04:44:00.837309+00:00 app[web.1]: Started POST "/application_controller/email" for 24.131.255.163 at 2013-06-24 04:44:00 +0000 
2013-06-24T04:44:00.845288+00:00 app[web.1]: Parameters: {"utf8"=>"✓", "authenticity_token"=>"MubEQddsKvR/QBLZtZKCt8TF9EiUSHjSTpxtSB5mAhE=", "message"=>"testing", "email"=>""} 
2013-06-24T04:44:00.845096+00:00 app[web.1]: Processing by ApplicationController#email as HTML 
2013-06-24T04:44:00.946113+00:00 app[web.1]: 
2013-06-24T04:44:00.946113+00:00 app[web.1]: Sent mail to [email protected] (16ms) 
2013-06-24T04:44:00.946346+00:00 app[web.1]: Completed 500 Internal Server Error in 101ms 
2013-06-24T04:44:00.948747+00:00 app[web.1]: 
2013-06-24T04:44:00.948747+00:00 app[web.1]: Errno::ECONNREFUSED (Connection refused - connect(2)): 
2013-06-24T04:44:00.948747+00:00 app[web.1]: app/controllers/application_controller.rb:5:in `email' 
2013-06-24T04:44:00.948747+00:00 app[web.1]: 
2013-06-24T04:44:00.948747+00:00 app[web.1]: 
2013-06-24T04:44:00.952511+00:00 heroku[router]: at=info method=POST path=/application_controller/email host=fast-reaches-9399.herokuapp.com fwd="24.131.255.163" dyno=web.1 connect=1ms service=126ms status=500 bytes=643 
2013-06-24T04:44:13.657925+00:00 app[web.1]: Started POST "/application_controller/email" for 24.131.255.163 at 2013-06-24 04:44:13 +0000 
2013-06-24T04:44:13.662188+00:00 app[web.1]: Processing by ApplicationController#email as HTML 
2013-06-24T04:44:13.662374+00:00 app[web.1]: Parameters: {"utf8"=>"✓", "authenticity_token"=>"MubEQddsKvR/QBLZtZKCt8TF9EiUSHjSTpxtSB5mAhE=", "message"=>"testing with test email", "email"=>"test email"} 
2013-06-24T04:44:13.690119+00:00 heroku[router]: at=info method=POST path=/application_controller/email host=fast-reaches-9399.herokuapp.com fwd="24.131.255.163" dyno=web.1 connect=3ms service=42ms status=500 bytes=643 
2013-06-24T04:44:13.690067+00:00 app[web.1]: app/controllers/application_controller.rb:5:in `email' 
2013-06-24T04:44:13.690067+00:00 app[web.1]: 
2013-06-24T04:44:13.686636+00:00 app[web.1]: 
2013-06-24T04:44:13.686636+00:00 app[web.1]: Sent mail to [email protected] (15ms) 
2013-06-24T04:44:13.690067+00:00 app[web.1]: Errno::ECONNREFUSED (Connection refused - connect(2)): 
2013-06-24T04:44:13.690067+00:00 app[web.1]: 
2013-06-24T04:44:13.690067+00:00 app[web.1]: 
2013-06-24T04:44:13.687154+00:00 app[web.1]: Completed 500 Internal Server Error in 25ms 
~/collegeanswerz 

+0

Что такое сообщение об ошибке 500? –

+0

'Нам очень жаль, но что-то пошло не так.' –

+0

В журнале не есть браузер? –

ответ

1

Вероятно, вы видели отказ в соединении, потому что вам не разрешено подключаться к локальному SMTP-серверу на Heroku, что запрещено.

Вам понадобится внешняя служба SMTP. У Heroku есть плагины для нескольких поставщиков, которые предлагают внешнюю службу SMTP, перечисленную на их странице аддонов: (https://addons.heroku.com/#email-sms). В каждом дополнении содержатся инструкции по настройке вашего приложения.

Вы также можете использовать стандартную почтовую службу, для которой у вас есть учетная запись, и настроить ее с помощью ActionMailer. Вы можете попробовать что-то подобное в своей конфигурации/environment/production.rb, если у вас есть учетная запись GMail.

http://guides.rubyonrails.org/action_mailer_basics.html#example-action-mailer-configuration

+0

Спасибо, это звучит многообещающе. Я сделаю это завтра утром. –

+0

Я установил его с помощью gmail, и он отлично работает, спасибо! Для тех, кто читает это, убедитесь, что ваше имя пользователя в production.rb завершено на @ gmail.com. Кроме того, я должен был что-то сделать с Google для аутентификации. Они думали, что это злонамеренный пользователь, и мне было предложено подтвердить, что это я. –

+0

На самом деле, у меня есть еще 2 вопроса: 1) как мне получить дружеское переадресацию? 2) как я могу разрешить пользователю вводить свой адрес электронной почты, чтобы я мог видеть, от кого оно происходит, но есть ли это необязательно? –

0

Из журнала поставляется ясно, что вы получите сообщение об ошибке, потому что Rails ActionMailer не удается подключиться к серверу SMTP. Для отладки этой проблемы в производстве вы можете изменить конфигурации в development.rb к этому:

config.action_mailer.raise_delivery_errors = true 

так что вы увидите рассыльщик исключений в развитии. Если у вас есть точная ошибка, вы можете обновить журнал для получения дополнительной справки.