简体   繁体   English

RAILS-如何允许用户向其个人页面添加音乐/定位播放列表?

[英]RAILS -how to allow user to add music/spotify playlists to their personal page?

For a ruby on rails school project(no intention to use publicly), I want to allow users to upload music playlist to their page, using something like spotify/soundcloud, Any ideas on how to implement this? 对于Rails学校项目上的ruby(无意公开使用),我想允许用户使用诸​​如spotify / soundcloud之类的东西将音乐播放列表上传到他们的页面,有关如何实现此目的的任何想法?

Mainly how to give the user the ability to choose what to add on their page, (eg. how instagram user upload an image, here user can upload their own songs/external playlists) 主要是如何使用户能够选择要在页面上添加的内容(例如instagram用户如何上传图片,此处用户可以上传自己的歌曲/外部播放列表)

(user history is not important) (用户历史记录不重要)

If you want to give the user the ability to upload an actual mp3 file (or similar), you should look into ActiveStorage / Paperclip / Carrierwave / Shrine . 如果要使用户能够上传实际的mp3文件(或类似文件),则应查看ActiveStorage / 回形针 / Carrierwave / Shrine ActiveStorage is closely coupled with Rails so it might be the easiest to get started with. ActiveStorage与Rails紧密相连,因此可能是最容易上手的。

If you use ActiveStorage you won't have to write the associations or the file fields; 如果您使用ActiveStorage,则不必编写关联或文件字段。 it'll do that for you. 会帮你的。 You'll simply have to drop in has_many_attached , and given your file field is called Song , it'll look something like: 您只需要放入has_many_attached ,并给您的文件字段称为Song ,它将类似于:

class User < ApplicationRecord
  has_many_attached :songs
end 

To start locally, you can configure your Rails app to just use your local storage; 要在本地启动,可以将Rails应用程序配置为仅使用本地存储。 you don't need to get messy with any remote storage until you need to (eg production). 除非需要(例如生产),否则您无需弄乱任何远程存储。

On the user's profile (given they have one), you can simply reference the songs , such as: 在用户的个人资料上(如果有的话),您可以简单地引用songs ,例如:

@user.songs.each do ... end

Rails is really scary at first. 起初,Rails真的很吓人。 It's opinionated and overwhelming. 它固执己见,势不可挡。 If you need more direction my email's in my profile :) I'm n00b friendly. 如果您需要更多指导,请在我的个人资料中找到我的电子邮件:)我是n00b友好的。

two different things here: 这里有两个不同的东西:

so for Spotify, you'd need to go through a system like TuneCore or another means to get source files in there. 因此对于Spotify,您需要通过TuneCore之类的系统或其他方法才能在其中获取源文件。 I think Soundcloud would probably get you there, but you could just have people upload to your site with Carrierwave. 我认为Soundcloud可能会带您到那里,但是您可以让人们通过Carrierwave上传到您的站点。 For audio processing, you will need to do some server work to make sure you have the packages (LAME is required for MP3 encoding. I know, silly name). 对于音频处理,您将需要做一些服务器工作以确保您拥有软件包(MP3编码需要LAME。我知道,这很愚蠢)。

https://github.com/carrierwaveuploader/carrierwave https://github.com/TrevorHinesley/carrierwave-audio https://github.com/carrierwaveuploader/carrierwave https://github.com/TrevorHinesley/carrierwave-audio

This would also allow you to have people upload their own profile picture or other images, etc. 这也可以让人们上传自己的个人资料图片或其他图像等。

From there, you can have any fields you like on a profile. 从那里,您可以在个人资料上拥有任何您喜欢的字段。 If you want to embed an instagram feed, etc. you'll need to tackle each one of those as you go. 如果要嵌入instagram feed等,则需要在处理过程中解决其中的每一个问题。 I'd start with the core piece, get that right, and then enhance. 我将从核心部分开始,做对,然后进行增强。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM