我正在尝试将每个播放列表的第一首歌加入到一系列播放列表中,并且我很难找到有效的解决方案.
我有以下型号:
class Playlist < ActiveRecord::Base
belongs_to :user
has_many :playlist_songs
has_many :songs, :through => :playlist_songs
end
class PlaylistSong < ActiveRecord::Base
belongs_to :playlist
belongs_to :song
end
class Song < ActiveRecord::Base
has_many :playlist_songs
has_many :playlists, :through => :playlist_songs
end
Run Code Online (Sandbox Code Playgroud)
我想得到这个:
playlist_name | song_name
----------------------------
chill | baby
fun | bffs
Run Code Online (Sandbox Code Playgroud)
我很难找到通过加入来实现这一目标的有效方法.
更新****
Shane Andrade带领我朝着正确的方向前进,但我仍然无法得到我想要的东西.
这是我能够得到的:
playlists = Playlist.where('id in (1,2,3)')
playlists.joins(:playlist_songs)
.group('playlists.id')
.select('MIN(songs.id) as song_id, playlists.name as playlist_name')
Run Code Online (Sandbox Code Playgroud)
这给了我:
playlist_name | song_id
---------------------------
chill | 1
Run Code Online (Sandbox Code Playgroud)
这很接近,但我需要第一首歌(根据id)的名字.
如何确定YouTube视频是实际视频还是静态图像?
由于使用youtube API可能无法实现,是否有使用javascript/jquery扫描窗口给定区域中的像素并确定它们是否已更改的解决方法?
我是新手,我正在构建一个非常简单的应用程序.我可以通过点击链接到标签生成的链接,从我的育种者索引页面(/育种者)导航到我的育种者展示页面(/ breeders /:breeder_id).但是,如果我手动导航到breeders/1或任何其他breeders.show路由,我会收到以下错误:
Error while loading route: ReferenceError: params is not defined
at Catapp.BreedersShowRoute.Ember.Route.extend.model
Run Code Online (Sandbox Code Playgroud)
我无法弄清楚我做了什么导致了这一点.
这就是我认为的相关代码:
//router.js
Catapp.Router.map(function() {
this.resource('breeders', function() {
this.route('new');
this.route('show', {path: '/:breeder_id'});
});
});
Catapp.IndexRoute = Ember.Route.extend({
redirect: function(){
this.transitionTo('breeders.index');
}
});
Catapp.BreedersIndexRoute = Ember.Route.extend({
model: function(){
return this.store.find('breeder');
}
});
Catapp.BreedersShowRoute = Ember.Route.extend({
model: function(){
return this.store.find('breeder', params.breeder_id);
}
});
Run Code Online (Sandbox Code Playgroud)
.
// breeders_controller.js
Catapp.BreedersController = Ember.ArrayController.extend({
sortProperties: ['id']
});
Run Code Online (Sandbox Code Playgroud) 我正在尝试使用 rancher REST api 创建容器并将其添加到 rancher 中的现有服务。
我希望以下请求会创建一个容器并将其添加到 atlas-mosquitto 堆栈和 mosquitto 服务(见标签)。
curl -u "${RANCHER_ACCESS_KEY}:${RANCHER_SECRET_KEY}" \
-X POST \
-H 'Accept: application/json' \
-H 'Content-Type: application/json' \
-d '{"count":1, "imageUuid":"docker:dummy/atlas/mosquitto:0.0.8", "name":"atlas-mosquitto_mosquitto_dummy_name", "startOnCreate":true, "labels": {"io.rancher.service.deployment.unit": "acdaf002-e1d0-4625-ba9c-3e1dbc584a14", "io.rancher.project.name": "atlas-mosquitto", "io.rancher.container.pull_image": "always", "io.rancher.scheduler.affinity:container_label_soft_ne": "io.rancher.stack_service.name=atlas-mosquitto/mosquitto", "io.rancher.service.launch.config": "io.rancher.service.primary.launch.config", "io.rancher.project_service.name": "atlas-mosquitto/mosquitto", "io.rancher.stack.name": "atlas-mosquitto", "io.rancher.stack_service.name": "atlas-mosquitto/mosquitto"}, "publishAllPorts":false, "privileged":false, "stdinOpen":false, "tty":false, "readOnly":false' \
'https://rancher-ha.dummy.info/v1/projects/1a29/containers'
Run Code Online (Sandbox Code Playgroud)
下面是身体的漂亮印刷品,以便于阅读:
{
"count": 1,
"imageUuid": "docker:dummy\/atlas\/mosquitto:0.0.8",
"name": "atlas-mosquitto_mosquitto_dummy_name",
"startOnCreate": true,
"labels": {
"io.rancher.service.deployment.unit": "acdaf002-e1d0-4625-ba9c-3e1dbc584a14",
"io.rancher.project.name": "atlas-mosquitto",
"io.rancher.container.pull_image": "always",
"io.rancher.scheduler.affinity:container_label_soft_ne": "io.rancher.stack_service.name=atlas-mosquitto\/mosquitto",
"io.rancher.service.launch.config": "io.rancher.service.primary.launch.config",
"io.rancher.project_service.name": "atlas-mosquitto\/mosquitto", …Run Code Online (Sandbox Code Playgroud) javascript ×2
associations ×1
ember-data ×1
ember.js ×1
function ×1
join ×1
jquery ×1
rancher ×1
rest ×1
ruby ×1
youtube ×1
youtube-api ×1