Forum: Ruby on Rails Expected ... to define

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
088898ce0d3d6d1c996ca2e21a3a7680?d=identicon&s=25 Jonathan Towell (jpapa)
on 2007-07-04 05:24
I found several topics that covered a similar error with controllers,
but mine is with a model, and none of the fixes previously mentioned
seemed to apply.

Here is the error:

Expected ./app/models/lab_result.rb to define Lab_result

C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activesupport-1.4.2/lib/active_support/dependencies.rb:249:in
`load_missing_constant'
C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activesupport-1.4.2/lib/active_support/dependencies.rb:452:in
`const_missing'
C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activesupport-1.4.2/lib/active_support/dependencies.rb:464:in
`const_missing'
C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activesupport-1.4.2/lib/active_support/dependencies.rb:260:in
`load_missing_constant'
C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activesupport-1.4.2/lib/active_support/dependencies.rb:468:in
`const_missing'
#{RAILS_ROOT}/app/controllers/visit_controller.rb:72:in `delete_lab'

Here is the method causing causing the error:

def delete_lab
  @lab_result = Lab_result.find(params[:id])
  if @lab_result.destroy
    flash[:notice] = "Lab results successfully deleted"
    redirect_to :action => 'update', :id => @lab_result.visit
  end
end

Here is the Lab_result model sitting comfortably in the models dir:

class LabResult < ActiveRecord::Base
  belongs_to :lab
  belongs_to :visit
end

Any advice?
2b891e820c238ded365d035771603f21?d=identicon&s=25 Bill Walton (Guest)
on 2007-07-04 05:40
(Received via mailing list)
Hi Jonathan,

Jonathan Towell wrote:

> Here is the error:
>
> Expected ./app/models/lab_result.rb to define Lab_result

> `const_missing'
> #{RAILS_ROOT}/app/controllers/visit_controller.rb:72:in `delete_lab'
>
> Here is the method causing causing the error:
>
> def delete_lab
>  @lab_result = Lab_result.find(params[:id])

> Here is the Lab_result model sitting comfortably in the models dir:
>
> class LabResult < ActiveRecord::Base

The find occurs on the model.  You're using some sort of combination of
the
model class and the model class file name.  Try:

@lab_result = LabResult.find(params[:id])

hth,
Bill
This topic is locked and can not be replied to.