feature/share-libs
rb 72 lines 1.76 KB
Raw
1 ActiveAdmin.register Song do
2 menu priority: 5, parent: 'Music Database'
3 permit_params :album_id, :name, :user_id, :description, :locale,
4 song_artists_attributes: %i[id artist_id primary _destroy]
5
6 index do
7 selectable_column
8 column :name
9 column :description do |song|
10 strip_tags song.description.truncate 150
11 end
12 column :album
13 column 'Lyrics' do |song|
14 if song.lyrics.count.positive?
15 song.lyrics.each_with_index do |lyric, index|
16 a "V #{(index + 1).to_s}", href: admin_lyric_url(lyric)
17 text_node ' '.html_safe
18 a 'Edit', href: edit_admin_lyric_url(lyric)
19 text_node '</br>'.html_safe
20 end
21 nil
22 else
23 link_to 'Add', "#{new_admin_lyric_path}?song_id=#{song.id.to_s}"
24 end
25 end
26 column :user
27 column :views_count
28 actions
29 end
30
31 filter :album
32 filter :artists
33 filter :views_count
34 filter :name
35 filter :description
36 filter :created_at
37 filter :updated_at
38
39 show do
40 attributes_table do
41 row :name
42 row :user
43 row :description do |song|
44 raw song.description
45 end
46 row :created_at
47 row :updated_at
48 end
49 end
50
51 form do |f|
52 f.inputs do
53 f.has_many :song_artists, heading: 'Artist(s)',
54 allow_destroy: true,
55 new_record: 'Tambah Artis' do |a|
56 a.input :artist
57 a.input :primary
58 end
59 end
60 f.inputs do
61 if f.object.new_record?
62 f.input :album, include_blank: false, selected: params[:album_id]
63 else
64 f.input :album, include_blank: false
65 end
66 f.input :user, include_blank: false
67 f.input :name
68 f.input :description, as: :quill_editor
69 end
70 f.actions
71 end
72 end