我对Rails比较陌生.我想为使用多态关联的模型添加关联,但只返回特定类型的模型,例如:
class Note < ActiveRecord::Base
# The true polymorphic association
belongs_to :subject, polymorphic: true
# Same as subject but where subject_type is 'Volunteer'
belongs_to :volunteer, source_association: :subject
# Same as subject but where subject_type is 'Participation'
belongs_to :participation, source_association: :subject
end
Run Code Online (Sandbox Code Playgroud)
我通过阅读有关ApiDock的关联尝试了大量的组合,但似乎没有任何东西完全符合我的要求.这是我迄今为止最好的:
class Note < ActiveRecord::Base
belongs_to :subject, polymorphic: true
belongs_to :volunteer, class_name: "Volunteer", foreign_key: :subject_id, conditions: {notes: {subject_type: "Volunteer"}}
belongs_to :participation, class_name: "Participation", foreign_key: :subject_id, conditions: {notes: {subject_type: "Participation"}}
end
Run Code Online (Sandbox Code Playgroud)
我希望它通过这个测试:
describe Note do
context 'on volunteer' do
let!(:volunteer) …Run Code Online (Sandbox Code Playgroud) 虽然git svn clone -s https://svn.example.com/repo/我收到了以下输出:
r3073 = a6132f3a937b632015e66d694250da9f606b8333 (refs/remotes/trunk)
Found possible branch point: https://svn.example.com/repo/trunk => https://svn.example.com/repo/branches/v1.3, 3073
W: Refspec glob conflict (ref: refs/remotes/trunk):
expected path: repo/branches/trunk
real path: repo/trunk
Continuing ahead with repo/trunk
W: Refspec glob conflict (ref: refs/remotes/trunk):
expected path: repo/branches/trunk
real path: repo/trunk
Continuing ahead with repo/trunk
W: Refspec glob conflict (ref: refs/remotes/trunk):
expected path: repo/branches/trunk
real path: repo/trunk
Continuing ahead with repo/trunk
W: Refspec glob conflict (ref: refs/remotes/trunk):
expected path: repo/branches/trunk
real path: repo/trunk
Continuing …Run Code Online (Sandbox Code Playgroud) 我正在使用Amazon Linux AMI并对其进行一些自定义修改(添加了axis2server等)并将其保存为新的AMI.现在我想要做的是当AMI启动时,启动axis2server(ie.saxis2server应该在实例启动时自动启动).为此,我使用了如下的init脚本并运行以下命令:
chkconfig --add axisservice
Run Code Online (Sandbox Code Playgroud)
但是当我从我的图像中启动一个新实例时,axis2server还没有开始.
我只需要在启动时执行脚本/home/ec2-user/axis2-1.6.1/bin/axis2server.sh.我在这里错过了什么吗?
#! /bin/sh
# Basic support for IRIX style chkconfig
###
# chkconfig: 235 98 55
# description: Manages the services you are controlling with the chkconfig command
###
case "$1" in
start)
echo -n "Starting axisservice"
touch ~/temp.txt
cd /home/ec2-user/axis2-1.6.1/bin
./axis2server.sh &
echo "."
;;
stop)
echo -n "Stopping axisservice"
echo "."
;;
*)
echo "Usage: /sbin/service axisservice {start|stop}"
exit 1
esac
exit 0
Run Code Online (Sandbox Code Playgroud)
我还浏览了https://help.ubuntu.com/community/CloudInit,它提供了一种名为User-Data Scripts的机制,用户可以在启动脚本时执行脚本.
$ euca-run-instances --key mykey …Run Code Online (Sandbox Code Playgroud) 我不得不频繁地离开电脑,我想触发一些命令,当我的iPhone离我的iMac足够远时(靠近它与2-3米远/墙的另一侧).几分钟的延迟很好.
我已经下载了reduxcomputing-proximity并且它可以工作,但这仅在设备进入/退出蓝牙范围时触发,但我想要的范围要小得多.
(接近轮询[IOBluetoothDevice -remoteNameRequest]以查看设备是否处于蓝牙范围内.)
[IOBluetoothDevice -rawRSSI]当我连接到iPhone时,我已经习惯了RSSI(当断开时它才会返回+127),但是为了节省iPhone的电池寿命,我宁愿避免建立完整的蓝牙连接.
我是否认为保持连接会比每隔几分钟轮询消耗更多的电池寿命?
我已经覆盖了这里的isInRange方法,proximity为我提供了一个工作解决方案,与以前的remoteNameRequest:方法相比,这可能是相对电池密集的:
- (BOOL)isInRange {
BluetoothHCIRSSIValue RSSI = 127; /* Valid Range: -127 to +20 */
if (device) {
if (![device isConnected]) {
[device openConnection];
}
if ([device isConnected]) {
RSSI = [device rawRSSI];
[device closeConnection];
}
}
return (RSSI >= -60 && RSSI <= 20);
}
Run Code Online (Sandbox Code Playgroud)
(Proximity使用同步调用 - 如果我符合我的需要,我会将其编辑为异步,但现在这并不重要.)
这个SO帖子引用了在'查询扫描'期间获得RSSI,听起来像我想要的,但它谈到使用Linux Bluez库,而我在Mac上 - …
我的xcode版本是3.2.5.
我的应用程序是在iPhone上创建的.我希望我为iPhone编写的应该运行并适用于iPad.如何解决这个问题?
帮帮我朋友,如何创建这种类型的应用程序?