在rails中实现编辑时未初始化的常量错误

时间:2013-03-22 09:07:23

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

我是ruby on rails的新手。 我正在尝试一个新的图书馆管理项目,但这样做我遇到了一个错误,

我得到的错误是uninitialized constant ActionView::CompiledTemplates::Library 当我试图在book_transactions中实现编辑时。

Extracted source (around line #23):

20:   <div class="control-group">
21:     <%= f.label :reason_id, :class => 'control-label' %>
22:     <div class="controls">
23:       <%= collection_select(:book_transaction, :reason_id, LovHelper.getLov(Library::Library::USER_TYPE_LOV), :id, :lov_value) %>
24:     </div>
25:   </div>
26:   <div class="control-group">

我的观点如下: -

<%= form_for @book_transaction, :html => { :class => 'form-horizontal' } do |f| %>
  <div class="control-group">
    <%= f.label :book_id, :class => 'control-label' %>
    <div class="controls">
      <%= collection_select(:book_transaction, :book_id, Book.all, :id, :title) %>
    </div>
  </div>
  <div class="control-group">
    <%= f.label :action_date, :class => 'control-label' %>
    <div class="controls">
      <%= f.datetime_select :action_date, :class => 'datetime_select' %>
    </div>
  </div>
  <div class="control-group">
    <%= f.label :num_copies, :class => 'control-label' %>
    <div class="controls">
      <%= f.number_field :num_copies, :class => 'number_field' %>
    </div>
  </div>
  <div class="control-group">
    <%= f.label :reason_id, :class => 'control-label' %>
    <div class="controls">
      <%= collection_select(:book_transaction, :reason_id, LovHelper.getLov(Library::Library::USER_TYPE_LOV), :id, :lov_value) %>
    </div>
  </div>
  <div class="control-group">
    <%= f.label :notes, :class => 'control-label' %>
    <div class="controls">
      <%= f.text_area(:notes, :size => '80x10', :class => 'text_field')%>
    </div>
  </div>
  <div class="control-group">
    <%= f.label :entered_by, :class => 'control-label' %>
    <div class="controls">
      <%= f.number_field :entered_by, :class => 'number_field' %>
    </div>
  </div>

  <div class="form-actions">
    <%= f.submit nil, :class => 'btn btn-primary' %>
    <%= link_to t('.cancel', :default => t("helpers.links.cancel")),
                book_transactions_path, :class => 'btn' %>
  </div>
<% end %>

我的表格如下: -

id serial NOT NULL,
  book_id integer,
  action_date timestamp without time zone,
  num_copies integer,
  reason_id integer,
  notes character varying(255),
  entered_by integer,
  created_at timestamp without time zone NOT NULL,
  updated_at timestamp without time zone NOT NULL,
  deleted integer NOT NULL DEFAULT 0,
  CONSTRAINT book_transactions_pkey PRIMARY KEY (id)

我的Lovhelper文件如下: -

module LovHelper

    #----------------------------------------------------------------------------  
    #  getLov - Get a list of values for a particular LOV type
    #----------------------------------------------------------------------------
    def self.getLov(lov_type)
        lovs = LovValue.unscoped
        lovs = lovs.select('lov_values.id, lov_value')
        lovs = lovs.joins(:lov_name)
        lovs = lovs.where('lov_names.name = ? ', lov_type)
        lovs = lovs.order('sequence asc')
        lovs.all

        return lovs     
    end

    #----------------------------------------------------------------------------  
    #  getValue - Get the value pertaining to a particular LOV Value id
    #----------------------------------------------------------------------------
    def self.getValue(lov_value_id)
        lov = LovValue.find(:all,
                                :select => 'lov_value',
                                :conditions => ['id = ? ', lov_value_id]).first
        return lov.lov_value
    end

    #----------------------------------------------------------------------------  
    #  getLovNames - Get a list of LOV names
    #----------------------------------------------------------------------------
    def self.getLovNames
        lov_names = LovName.all
        return lov_names
    end

end

现在我已经给出的代码是由我的大四学生实现的,所以理解它有一些问题。

任何人都可以向我解释为什么我收到此错误。

0 个答案:

没有答案