启动生产服务器时出现“未定义的局部变量或方法”

时间:2011-11-27 04:29:15

标签: ruby-on-rails

当我尝试在生产服务器中启动我的应用时,我收到错误:

/users_controller.rb:3: undefined local variable or method `signup_url' for UsersController:Class (NameError)

引用的代码在我的users_controller

class UsersController < ApplicationController
  if User.find(:all).empty?
    redirect_to signup_url, :notice => "Please make the first Administrator account."
  else
    before_filter :authorize
    before_filter :office_or_admin_only
  end

在我的routes.rb

match 'signup' => 'users#new', :as => :signup

这一切在开发中都很好用。这是第一次运行生产服务器,我创建并编制了生产数据库,但我已经对我的应用程序中的任何文件进行了更改。我需要在配置文件中运行生产模式吗?或者我的代码有问题吗?

2 个答案:

答案 0 :(得分:1)

不知道为什么会这样呈现,但......这就是问题所在。

我有一个递归循环,其来源是上面的第3行。

我这样修好了:

class UsersController < ApplicationController
  if User.find(:all).empty?
    before_filter :authorize, :except => [:create, :new]
  else
    before_filter :authorize
    before_filter :office_or_admin_only
  end

application_controller.rb

def authorize
  unless User.find_by_id(session[:user_id])
    if User.find(:all).empty?
      redirect_to signup_url, :notice => "Please make the first Administrator account."
    else
      redirect_to login_url
    end
  end
end

当users表为空时,这会使所有内容重定向到sign_up url,但是当users表为空时,通过为使用sign_up url调用的方法的过滤器添加异常来避免递归过滤。

我通过在开发中重置db以使条件与尝试的生产条件相同来解决这个问题。服务器启动很好,但是我的浏览器告诉我在导航到localhost:3000时有一个递归循环。

答案 1 :(得分:0)

尝试link_to :signuplink_to new_user_path