Heroku - 没有路线匹配

时间:2012-12-21 21:42:18

标签: ruby-on-rails ruby heroku

部署到Heroku后出现问题。试图访问/ sign_ups / new我在日志中看到了这一点。

2012-12-21T21:36:21+00:00 app[web.1]: Started GET "/sign_ups/new" for ... at 2012-12-21 21:36:21 +0000
2012-12-21T21:36:21+00:00 app[web.1]: 
2012-12-21T21:36:21+00:00 app[web.1]: ActionController::RoutingError (No route matches {:controller=>"sign_ups", :action=>"referral", :id=>nil}):
2012-12-21T21:36:21+00:00 app[web.1]:   app/helpers/sign_up_helper.rb:3:in `referral_link'
2012-12-21T21:36:21+00:00 app[web.1]:   app/views/sign_ups/show.html.erb:10:in `_app_views_sign_ups_show_html_erb__2538320905600276551_36877720'
2012-12-21T21:36:21+00:00 heroku[router]: at=info method=GET path=/sign_ups/new host=blah.herokuapp.com fwd=... dyno=web.1 queue=0 wait=0ms connect=2ms service=19ms status=404 bytes=728
2012-12-21T21:36:21+00:00 app[web.1]:   app/controllers/sign_ups_controller.rb:10:in `new'
2012-12-21T21:36:21+00:00 app[web.1]: 
2012-12-21T21:36:21+00:00 app[web.1]: 
2012-12-21T21:36:21+00:00 heroku[router]: at=info method=GET path=/favicon.ico host=blah.herokuapp.com fwd=... dyno=web.1 queue=0 wait=0ms connect=2ms service=4ms status=304 bytes=0

但是,如果我在heroku上运行rake路由,我会看到这一点。

  referrals GET  /r/:id(.:format)        sign_ups#referral
   sign_ups POST /sign_ups(.:format)     sign_ups#create
new_sign_up GET  /sign_ups/new(.:format) sign_ups#new
    sign_up GET  /sign_ups/:id(.:format) sign_ups#show
       root      /                       sign_ups#new

即使在作为生产模式运行时,一切都在本地运行良好。我缺少什么想法?

sign_ups_controller.rb

class SignUpsController < ApplicationController
  def new
    @sign_up = SignUp.find_by_remember_token(cookies[:remember_token])
    if @sign_up.nil?
      @sign_up = SignUp.new
    else
      render :show
    end
  end

  def create
    @sign_up = SignUp.new(params[:sign_up])
    if @sign_up.save
      cookies.permanent[:remember_token] = @sign_up.remember_token
      flash[:notice] = 'Thanks for signing up!'
      redirect_to root_path
    else
      render action: "new"
    end
  end

  def referral
    @sign_up = SignUp.new
    render action: "new"
  end
end

sign_ups_helper.rb

module SignUpHelper
  def referral_link(referral_id)
    URI::join(root_url, referrals_path(referral_id))
  end
end

1 个答案:

答案 0 :(得分:0)

解决了这个问题。它与迁移有关。我在单独的迁移中添加了referral_id,但没有设置默认值。