Ruby on rails 3号铁路-乘客通道问题
我的应用程序在任何需要文件的控制器或模型上返回错误。 通常我需要一个如下所示的文件Ruby on rails 3号铁路-乘客通道问题,ruby-on-rails,apache,ubuntu,passenger,Ruby On Rails,Apache,Ubuntu,Passenger,我的应用程序在任何需要文件的控制器或模型上返回错误。 通常我需要一个如下所示的文件 require '/lib/position_mover' 我对它进行了一些研究,如果我在下面的服务器顶部目录中指定一个路径,它似乎可以工作 require '/srv/www/testapp/lib/position_mover' 我想使用相对路径有很多原因。有人能告诉我这方面的方向吗 服务器配置: <VirtualHost 173.255.238.220> ServerName tes
require '/lib/position_mover'
我对它进行了一些研究,如果我在下面的服务器顶部目录中指定一个路径,它似乎可以工作
require '/srv/www/testapp/lib/position_mover'
我想使用相对路径有很多原因。有人能告诉我这方面的方向吗
服务器配置:
<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>
- 阿帕奇2
- Ubuntu 10.10
- rails 3.0.3
- ruby 1.9.2p0
- mysql
<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>
ServerName test.targetsft.com
DocumentRoot/srv/www/testapp/public/
Passengeraproot/srv/www/testapp/
通融
选项-多视图
如果您需要Rails应用程序的lib
目录中的文件,则无需这样做。默认情况下,Rails需要其中的所有内容。感谢您的回复!虽然插件是lib文件夹的事实,但实际上我在这里调用了自己的自定义模块。我尝试从模型顶部取出require部分,但除非我在文件顶部要求它,否则我会得到一个未定义常量的错误。必须有一种方法设置乘客,使其在默认情况下在自己的目录中查找
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
模块位置移动器
def移动到位置(新位置)
最大位置=self.class.where(位置范围).count
#确保新位置为1..max\u位置中的整数
除非是新职位。零?
新位置=[[1,新位置。到i].max,max\u位置].min
结束
如果位置==新位置#什么也不做
返回真值
艾尔西夫位置。零?
增量项目(新职位,1000000)
elsif新职位。无?
递减项(位置+1000000)
elsif新位置<位置
增量项目(新位置,位置1)
elsif新位置>位置
减量项目(位置+1,新位置)
结束
返回更新位置属性(:位置,新位置)
结束
def定位镜
"1=1"
结束
def增量_项目(第一个、最后一个)
items=self.class.where([“position>=?和position=?和position您需要将此模块放置在lib
目录中,然后将其添加到config/application.rb
文件中的config.autoload\u路径中(默认情况下,该设置被注释掉)。当您在代码中引用此模块时,Rails将自动知道需要lib
目录中的文件。遗憾的是,Rails 3中不再存在此文件,您现在需要手动进行请求。或者您可以将其添加到自动加载路径设置中,当引用其常量时,将自动加载这些文件