I have a module called EntityTrackerHelper. Here is the code:
module EntityTrackerHelper
def self.createUserAction(user_id, type, entity_id)
existingua = UserAction.find(:first, :conditions=> ["user_id = ? and type = ? and entity_id=?", user_id, type, entity_id])
if existingua.nil?
ua = UserAction.new
ua.user_id = user_id
ua.type = type
ua.entity_id = entity_id
ua.date = Time.now
ua.save
else
existingua.date = Time.now
existingua.save
end
end
end
It is used to track changes and user access in an entity. It is used in a controller as follows.
require "#{Rails.root}/lib/EntityTrackerHelper"
class LessonSectionsController < InheritedResources::Base
def index
user_id = params[:user_id]
lesson_id = params[:lesson_id]
EntityTrackerHelper::createUserAction(user_id, 'LESSON', lesson_id)
lessonSections = LessonSection.find(:all, :conditions => { :lesson_id => params[:lesson_id] })
render :json => {:sections => lessonSections.as_json({:only => [:lesson_id,:id,:name]}), :error => ''}
end
end
I get the following error:
LoadError (Expected /<ProjPath>/<ProjName>/app/models/lesson.rb to define LESSON):
lib/EntityTrackerHelper.rb:12:in `createUserAction'
app/controllers/lesson_sections_controller.rb:9:in `index'
Line 12 in EntityTrackerHelper is UserAction.find...
Any idea?
Thanks
app/models/lesson.rb. Anyway, see my answer, I guess that's the reason why it is searching forLESSONin this file.