My application returns and error on any controller or model that needs personal files. typically I'd need a file as proven below.

require '/lib/position_mover'

I performed around by using it a bit also it appears to operate basically specify a path in the top directory of my server show below.

require '/srv/www/testapp/lib/position_mover'

I wish to make use of the relative path for a lot of reasons. Can someone produce direction about this?

Server config:

  • Apache 2
  • Ubuntu 10.10
  • rails 3..3
  • ruby 1.9.2p0
  • mysql

Virtual host:

<VirtualHost 173.255.238.220>
    ServerName test.targesoft.com
    DocumentRoot /srv/www/testapp/public/
    <Directory /srv/www/testapp/public/>
        PassengerAppRoot /srv/www/testapp/
        Allow from all
        Options -MultiViews
    </Directory>
</VirtualHost>

If you are needing personal files within the lib directory of the Rails application, that isn't necessary. Rails requires my way through there automatically.

Just response! While plug ins would be the defacto for that lib folder, I am really bringing in my very own custom module here. I attempted using the require piece from the top model, but unless of course I want it a the top my file, I recieve a mistake to have an undefined constant. There has to be a method to setup passenger to ensure that it appears in it's own directory automatically.

module PositionMover

  def move_to_position(new_position)
    max_position = self.class.where(position_scope).count
    # ensure new_position is an integer in 1..max_position
      unless new_position.nil?
        new_position = [[1, new_position.to_i].max, max_position].min
      end

      if position == new_position # do nothing
        return true
      elsif position.nil? 
        increment_items(new_position, 1000000)
      elsif new_position.nil? 
        decrement_items(position+1, 1000000)
      elsif new_position < position 
        increment_items(new_position, position-1)
      elsif new_position > position
        decrement_items(position+1, new_position)
      end
      return update_attribute(:position, new_position)
    end


   def position_scope
    "1=1" 
   end

   def increment_items(first, last)
     items = self.class.where(["position >= ? and position <= ? AND #{position_scope}", first, last])
     items.each {|i| i.update_attribute(:position, i.position + 1)}
   end


   def decrement_items(first, last)
      items = self.class.where(["position >= ? and position <= ? AND #{position_scope}", first, last])
      items.each {|i| i.update_attribute(:position, i.position - 1)}
    end


end

You will want to place this module within the lib directory after which combine it with config.autoload_paths inside your config/application.rb file (an environment which, automatically, is said out). Whenever you reference this module inside your code, Rails will instantly know to want the file within the lib directory.