Associate a user to his playlists
This commit is contained in:
@@ -8,7 +8,7 @@ class PlaylistsController < ApplicationController
|
||||
end
|
||||
|
||||
def create
|
||||
@playlist = Playlist.new(:name => params[:playlist][:name])
|
||||
@playlist = current_user.playlists.build(params[:playlist])
|
||||
if @playlist.save
|
||||
redirect_to :action => 'index'
|
||||
else
|
||||
|
@@ -1,3 +1,6 @@
|
||||
class Playlist < ActiveRecord::Base
|
||||
belongs_to :user
|
||||
|
||||
validates_presence_of :user_id
|
||||
validates_presence_of :name
|
||||
end
|
||||
|
@@ -6,6 +6,8 @@ class User < ActiveRecord::Base
|
||||
attr_reader :password
|
||||
attr_accessible :email, :password, :password_confirmation
|
||||
|
||||
has_many :playlists
|
||||
|
||||
validates_presence_of :email, :password_hash
|
||||
validates_confirmation_of :password
|
||||
|
||||
|
Reference in New Issue
Block a user