表单页面在本地工作但不在Heroku上?

时间:2014-06-21 22:22:04

标签: ruby-on-rails heroku devise

我的rails应用程序有一个两阶段注册,我使用Devise gem。它似乎在我的本地服务器上运行得很好,但是在heroku上(使用postgres数据库),完成第一个表单会重定向到错误页面(heroku的迷人"出了问题")而不是而不是第二种形式。我无法在heroku的日志中找到原因。

这是第一个表单页面:

<h3>Create your Profile</h3>
<%= form_for(resource, as: resource_name, url: registration_path(resource_name)) do |f| %>
    <%= render 'shared/error_messages'%>
    <div class="form-group">
    <%= f.text_field :name, class: 'form-control', autofocus: true, placeholder: 'Name Shown to Providers' %>
    </div>
    <div class= "form-group">
        <%= f.text_field :email, class: 'form-control', autofocus: true, placeholder: 'Email'%>
    </div>
    <div class="form-group">
    <%= f.password_field :password, class: 'form-control', autofocus: true, placeholder: 'Password'%>
    </div>
    <div class="form-group">
        <%= f.password_field :password_confirmation, class: 'form-control', autofocus: true, placeholder: 'Confirm Password'%>
    </div>

    <%= f.submit "Submit", class: "btn btn-large btn-primary" %>
<% end %>

这是第二个:

<h3>Populate Your Profile</h3>
<div id="popform">
<div class="row">
    <aside class="span4">
    <section>
    <img src=<%= @user.avatar.url(:small) %> id="prof" class= "img-circle"/>
    <h1> 
        <%= @user.name %>
    </h1>
    </section>
    </aside>
</div>
<div id='usereditform'>
    <%= form_for(resource, as: resource_name, url: registration_path(resource_name), html: { method: :put }) do |f| %>
        <div class="form-group">
            <%= f.label :avatar%>
            <%= f.file_field :avatar%>
        </div>
        <div class="form-group">
            <%= f.label :industry%>
            <%= f.select :industry, [['Please select an industry',nil],'Professional Services','Graphic Design','Marketing','Web Development'], class: 'form-control'%>
        </div>
        <div class= "form-group">
            <%= f.text_field :city, class: 'form-control', autofocus: true, placeholder: 'City'%>
        </div>
        <div class="form-group">
            <%= f.label :state%>
            <%= f.select :state, options_for_select(us_states, "CA"), class: 'form-control'%>
        </div>
        <div class="form-group">
            <%= f.text_field :website, class: 'form-control', autofocus: true, placeholder: 'Website (if applicable)'%>
        </div>
        <div class= "form-group">
            <%= f.text_field :description, class: 'form-control', id: 'dfield', autofocus:true,placeholder: 'Description' %>
        </div>
        <div class= "form-group">
            <%= f.submit "Submit", class: "btn btn-large btn-primary" %>
        </div>
    </div>
<% end%>

这是我的稍微过度设计注册控制器:

class RegistrationsController < Devise::RegistrationsController
    protected
    def after_sign_up_path_for(resource)
        if resource.is_a?(User)
            edit_user_registration_path
        else
            super
        end
    end
    def after_inactive_sign_up_path_for(resource)
        if resource.is_a?(User)
            edit_user_registration_path
        else
            super
        end
    end
end

根据要求,这是我的config / routes.rb:

Rails.application.routes.draw do
    devise_for :providers
    devise_for :users, :controllers => {:registrations => "registrations"}
    resources :users
    resources :providers
    root :to=>'pages#home'
    match '/home', to: 'pages#home', via: 'get'
end

最后,这是我的heroku日志的最后几行:

2014-06-21T21:32:44.872651+00:00 app[web.1]:   vendor/bundle/ruby/2.1.0/gems/activerecord     4.1.1/lib/active_record/query_cache.rb:36:in `call'
2014-06-21T21:32:44.872662+00:00 app[web.1]:   vendor/bundle/ruby/2.1.0/gems/actionpack-4.1.1/lib/action_dispatch/middleware/remote_ip.rb:76:in `call'
2014-06-21T21:32:44.872664+00:00 app[web.1]:   vendor/bundle/ruby/2.1.0/gems/actionpack-4.1.1/lib/action_dispatch/middleware/debug_exceptions.rb:17:in `call'
2014-06-21T21:32:44.872665+00:00 app[web.1]:   vendor/bundle/ruby/2.1.0/gems/actionpack-4.1.1/lib/action_dispatch/middleware/show_exceptions.rb:30:in `call'
2014-06-21T21:32:44.872644+00:00 app[web.1]:   vendor/bundle/ruby/2.1.0/gems/actionpack-4.1.1/lib/action_dispatch/middleware/params_parser.rb:27:in `call'
2014-06-21T21:32:44.872650+00:00 app[web.1]:   vendor/bundle/ruby/2.1.0/gems/actionpack-4.1.1/lib/action_dispatch/middleware/cookies.rb:560:in `call'
2014-06-21T21:32:44.872673+00:00 app[web.1]:   vendor/bundle/ruby/2.1.0/gems/railties-4.1.1/lib/rails/rack/logger.rb:20:in `call'
2014-06-21T21:32:44.872675+00:00 app[web.1]:   vendor/bundle/ruby/2.1.0/gems/actionpack-4.1.1/lib/action_dispatch/middleware/request_id.rb:21:in `call'
2014-06-21T21:32:44.872676+00:00 app[web.1]:   vendor/bundle/ruby/2.1.0/gems/rack-1.5.2/lib/rack/methodoverride.rb:21:in `call'
2014-06-21T21:32:44.872682+00:00 app[web.1]:   vendor/bundle/ruby/2.1.0/gems/rack-1.5.2/lib/rack/sendfile.rb:112:in `call'
2014-06-21T21:32:44.872666+00:00 app[web.1]:   vendor/bundle/ruby/2.1.0/gems/railties-4.1.1/lib/rails/rack/logger.rb:38:in `call_app'
2014-06-21T21:32:44.872654+00:00 app[web.1]:   vendor/bundle/ruby/2.1.0/gems/actionpack-4.1.1/lib/action_dispatch/middleware/callbacks.rb:29:in `block in call'
2014-06-21T21:32:44.872672+00:00 app[web.1]:   vendor/bundle/ruby/2.1.0/gems/activesupport-4.1.1/lib/active_support/tagged_logging.rb:68:in `tagged'
2014-06-21T21:32:44.872594+00:00 app[web.1]:   vendor/bundle/ruby/2.1.0/gems/actionpack-4.1.1/lib/action_controller/metal/params_wrapper.rb:250:in `process_action'
2014-06-21T21:32:44.872592+00:00 app[web.1]:   vendor/bundle/ruby/2.1.0/gems/actionpack-4.1.1/lib/action_controller/metal/instrumentation.rb:30:in `process_action'
2014-06-21T21:32:44.872585+00:00 app[web.1]:   vendor/bundle/ruby/2.1.0/gems/actionpack-4.1.1/lib/action_controller/metal/instrumentation.rb:31:in `block in process_action'
2014-06-21T21:32:44.872603+00:00 app[web.1]:   vendor/bundle/ruby/2.1.0/gems/actionpack-4.1.1/lib/action_controller/metal.rb:231:in `block in action'
2014-06-21T21:32:44.872597+00:00 app[web.1]:   vendor/bundle/ruby/2.1.0/gems/actionpack-4.1.1/lib/abstract_controller/base.rb:136:in `process'
2014-06-21T21:32:44.872605+00:00 app[web.1]:   vendor/bundle/ruby/2.1.0/gems/actionpack-4.1.1/lib/action_dispatch/routing/route_set.rb:80:in `dispatch'
2014-06-21T21:32:44.872678+00:00 app[web.1]:   vendor/bundle/ruby/2.1.0/gems/rack-1.5.2/lib/rack/runtime.rb:17:in `call'

2 个答案:

答案 0 :(得分:2)

您确定已正确配置数据库吗?您的错误日志似乎表明它尝试做的最后一件事是访问数据库,可能是将信息插入您的用户表。生产中此类型的故障不仅会导致事务失败,还会导致整个应用程序崩溃。

答案 1 :(得分:0)

我有一个在 localhost 上运行良好的表单,但在 heroku 上却无法运行。

对我来说,我必须在迁移正常工作之前重新启动 heroku

heroku restart

然后一切都按预期进行。我现在在每组迁移后运行 heroku restart。我不确定它是否记录在任何地方,但除非重新启动,否则它们并不总是有效,所以我这样做只是为了安全。