为什么我从Rails获得“未初始化的常量”?

时间:2013-07-18 05:17:39

标签: ruby ruby-on-rails-3 ruby-on-rails-3.2

我创建了一条路线:

user_currency GET    /user/currency/:currency(.:format)        user#currency

这是我的用户控制器:

class UsersController < ApplicationController 
require 'will_paginate/array' 
require 'gdata'       
before_filter :ensure_user_friendly_url, :only => [:show, :following, :followers, :friends, :designers]
before_filter :check_if_signed_in, :only => :signup

路线的控制器:

def currency
session[:currency] = params[:currency]
redirect_to :back
end

我收到错误:

uninitialized constant UserController

此处发生错误:

- currency_values.each do |currency|
    %li 
      = link_to "#{currency.country}", user_currency_url(currency.id)

我将currency_id作为货币传递。

1 个答案:

答案 0 :(得分:2)

在您的路线声明中,您错误地引用了控制器名称。它应该是:

user_currency GET    /user/currency/:currency(.:format)        users#currency

基本上您的控制器为UsersController而不是UserController