新用户注册该网站后,应将其重定向到交易索引。这在开发环境中正常工作,但它在生产中不起作用(在Heroku上)。在生产中,它会重定向到用户索引(不存在)。
这是我的用户控制器:
class UsersController < ApplicationController
def new
@user = User.new
end
def create
@user = User.new(params[:user])
if valid_email? @user.email
@user.save
redirect_to deals_path
else
flash[:error] = "Please enter a valid email address"
redirect_to root_path
end
end
private
def valid_email?(email)
valid_email_regex = /\A.+@.+\..+\z/i
email =~ valid_email_regex
end
end
这是routes.rb:
root to: 'users#new'
resources :deals, only: [:index]
resources :users, only: [:new, :create]
这是rake路线的结果,RAILS_ENV =生产佣金路线(两者都相同):
root / users#new
deals GET /deals(.:format) deals#index
users POST /users(.:format) users#create
new_user GET /users/new(.:format) users#new
在开发过程中一切正常,但在生产中,它的行为就像用户控制器中的“redirect_to deals_path”行不存在一样。
应用程序在开发中使用SQLite,在生产中使用PostgreSQL,这可能与它有关吗?
该应用程序位于rails 3中并托管在Heroku上。
答案 0 :(得分:0)
原来问题是用户模型上的before_save过滤器发送了无法正常工作的欢迎电子邮件。我删除了之前的过滤器,现在工作正常。以下是感兴趣的任何人的服务器日志:
2013-04-08T03:14:07+00:00 app[web.1]: Started POST "/users" for xx.xxx.xx.xxx at 2013-04-08 03:14:07 +0000
2013-04-08T03:14:08+00:00 app[web.1]: Processing by UsersController#create as HTML
2013-04-08T03:14:08+00:00 app[web.1]: Parameters: {"utf8"=>"✓", "authenticity_token"=>"b4ysVip3iTm8LZmeRxHX3EdX/pH7X6c6SpgF11IpQis=", "user"=>{"email"=>"user@example.com"}, "commit"=>"Sign up"}
2013-04-08T03:14:08+00:00 app[web.1]: Rendered user_mailer/welcome_email.html.erb (10.9ms)
2013-04-08T03:14:08+00:00 app[web.1]:
2013-04-08T03:14:08+00:00 app[web.1]: Sent mail to user@example.com (54ms)
2013-04-08T03:14:08+00:00 app[web.1]: Completed 500 Internal Server Error in 344ms
2013-04-08T03:14:08+00:00 app[web.1]:
2013-04-08T03:14:08+00:00 app[web.1]: SocketError (getaddrinfo: Name or service not known):
2013-04-08T03:14:08+00:00 app[web.1]: app/models/user.rb:24:in `welcome_email'
2013-04-08T03:14:08+00:00 app[web.1]: app/models/user.rb:15:in `block in <class:User>'
2013-04-08T03:14:08+00:00 app[web.1]: app/controllers/users_controller.rb:10:in `create'
2013-04-08T03:14:08+00:00 app[web.1]:
2013-04-08T03:14:08+00:00 app[web.1]:
2013-04-08T03:14:08+00:00 heroku[router]: at=info method=POST path=/users host=www.xxx.com fwd="xx.xxx.xx.xxx" dyno=web.1 connect=1ms service=555ms status=500 bytes=0
2013-04-08T03:14:06+00:00 heroku[web.1]: State changed from starting to up