Associate a user to his playlists

This commit is contained in:
Thibault Jouan
2011-08-30 10:50:05 +00:00
parent 4f66db2682
commit 7fad9e0402
9 changed files with 48 additions and 7 deletions

View File

@@ -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

View File

@@ -1,3 +1,6 @@
class Playlist < ActiveRecord::Base
belongs_to :user
validates_presence_of :user_id
validates_presence_of :name
end

View File

@@ -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