Add basic playlists management
* Index of playlists * Create a new playlist * Basic playlist model with mandatory name
This commit is contained in:
18
app/controllers/playlists_controller.rb
Normal file
18
app/controllers/playlists_controller.rb
Normal file
@@ -0,0 +1,18 @@
|
||||
class PlaylistsController < ApplicationController
|
||||
def index
|
||||
@playlists = Playlist.all
|
||||
end
|
||||
|
||||
def new
|
||||
@playlist = Playlist.new
|
||||
end
|
||||
|
||||
def create
|
||||
@playlist = Playlist.new params[:playlist]
|
||||
if @playlist.save
|
||||
redirect_to :action => 'index'
|
||||
else
|
||||
render :action => 'new'
|
||||
end
|
||||
end
|
||||
end
|
3
app/models/playlist.rb
Normal file
3
app/models/playlist.rb
Normal file
@@ -0,0 +1,3 @@
|
||||
class Playlist < ActiveRecord::Base
|
||||
validates_presence_of :name
|
||||
end
|
4
app/views/playlists/index.html.haml
Normal file
4
app/views/playlists/index.html.haml
Normal file
@@ -0,0 +1,4 @@
|
||||
= link_to 'Create playlist', new_playlist_path
|
||||
%ul
|
||||
- @playlists.each do |p|
|
||||
%li= p.name
|
4
app/views/playlists/new.html.haml
Normal file
4
app/views/playlists/new.html.haml
Normal file
@@ -0,0 +1,4 @@
|
||||
= form_for @playlist do |f|
|
||||
= f.label :name
|
||||
= f.text_field :name
|
||||
= f.submit 'Create'
|
Reference in New Issue
Block a user