简体   繁体   中英

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?

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)

(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 . ActiveStorage is closely coupled with Rails so it might be the easiest to get started with.

If you use ActiveStorage you won't have to write the associations or the file fields; 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:

class User < ApplicationRecord
  has_many_attached :songs
end 

To start locally, you can configure your Rails app to just use your local storage; 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:

@user.songs.each do ... end

Rails is really scary at first. It's opinionated and overwhelming. If you need more direction my email's in my profile :) I'm n00b friendly.

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. I think Soundcloud would probably get you there, but you could just have people upload to your site with 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).

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. I'd start with the core piece, get that right, and then enhance.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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