我能够成功设置ActionCable,收听频道,验证请求等等.但是,在创建后尝试连接到频道时,我遇到了一个奇怪的错误(很难解释,见下文)
我有一个设置,一个配置文件有一个墙,墙上有很多帖子.每个帖子都有自己的频道,墙本身也有自己的频道.在墙上创建帖子时,会通过ActionCable进行更新:
# Wall's Cable Channel
class WallsChannel < ApplicationCable::Channel
def subscribed
profile = Profile.find_by_id params[:id]
if ability.can? :subscribe, profile
stream_from "Wall(#{profile.id})"
else
reject
end
end
end
# Broadcasting to the wall
ActionCable.server.broadcast 'Wall(:id:)', { :data: }
# Client Side
GlobalCable.cable.subscriptions.create({channel: 'WallsChannel', id :id: }, {
received: function(data) {
// do stuff with a new post on a wall
}
});
Run Code Online (Sandbox Code Playgroud)
我简化了它,但这可以按预期工作.创建新帖子时,墙上频道会被触发,客户端会收到帖子和所有商品.
问题是连接广播的新帖子.当我去听新帖子时,它无法从数据库中获取帖子:
# Posts Cable Channel
class PostsChannel < ApplicationCable::Channel
def subscribed
post = Post.find_by_id params[:id]
if ability.can? :subscribe, …Run Code Online (Sandbox Code Playgroud) 我试图在终端中使用多个参数运行我的rake任务,但是我一直收到错误:
rake populate:user['a' 'a']
DL is deprecated, please use Fiddle
rake aborted!
Don't know how to build task 'populate:user[a'
Run Code Online (Sandbox Code Playgroud)
我的rake文件:
namespace :populate do
desc 'Populate data into our database'
task :user, [:username, :password] => :environment do |t, args|
// do stuff, also doesn't work when I delete everything inside here
end
end
Run Code Online (Sandbox Code Playgroud)
我也试过了
rake populate:user[a, a]
Run Code Online (Sandbox Code Playgroud)
它运行时没有任何参数:
rake populate:user
Run Code Online (Sandbox Code Playgroud) 我有一个固定的背景图像附加到body标签,图像是2048px乘2048px并且是顶部居中:
body {
background: url(images/background.jpg) 50% 0% no-repeat fixed;
}
Run Code Online (Sandbox Code Playgroud)
我想在背景中添加一些动作,以便在观众浏览网站时平移整个图像
使用:https://github.com/brandonaaron/jquery-cssHooks/blob/master/bgpos.js来规范化背景位置属性,我可以按如下方式设置图像的动画:
$('body').animate({
backgroundPositionX: '100%',
backgroundPositionY: '100%'
}, 10000, 'linear');
Run Code Online (Sandbox Code Playgroud)
我想要添加随机移动,而不是在10秒内向右下方移动.
使用设置间隔我可以每隔10秒为图像设置动画,但如何确定背景位置百分比?当图像移动时,它应该是相同的速度,只是随机位置
var currX = 50;
var currY = 0;
$(function () {
animate();
window.setInterval(animate(), 10000);
});
function animate() {
var newPosX = currX - (Math.random() * 50);
var newPosY = currY - (Math.random() * 50);
$('body').animate({
backgroundPositionX: newPosX + '%',
backgroundPositionY: newPosY + '%'
}, 10000, 'linear');
}
Run Code Online (Sandbox Code Playgroud)
编辑:更好地描述我想做的事情的小提琴:http://jsfiddle.net/97w7f3c8/4/
我在Codeigniter中运行此查询
$query = $this->db->query("SELECT count(*) FROM `friends` WHERE uid=$logged_id AND who=$id")
Run Code Online (Sandbox Code Playgroud)
但桌子上的朋友们都是空的,他们内心也没什么
if($query->num_rows() > 0) {
return $query->num_rows();
}
Run Code Online (Sandbox Code Playgroud)
上面的查询返回1,当它显然应该返回0
也修改了查询
$query = $this->db->query("SELECT id FROM `friends` WHERE uid=$logged_id AND who=$id")
Run Code Online (Sandbox Code Playgroud)
按预期给我0
关于伯爵(*)的一些特别之处我不知道吗?