initial musician / band dev

This commit is contained in:
Brian Smith 2012-10-29 06:45:47 -04:00
parent d6d60ecc17
commit 662fcf0112
5 changed files with 63 additions and 5 deletions

View File

@ -19,6 +19,7 @@ require "jam_ruby/models/music_session"
require "jam_ruby/models/invitation"
require "jam_ruby/models/friend_request"
require "jam_ruby/models/instrument"
require "jam_ruby/models/user_instrument"
include Jampb

View File

@ -1,10 +1,22 @@
module JamRuby
class Band < ActiveRecord::Base
attr_accessor :photo_url, :logo_url
self.primary_key = 'id'
has_and_belongs_to_many :users, :class_name => "JamRuby::User"
has_many :genres, :class_name => "JamRuby::Genre"
def photo_url
# TODO: move image path to config
@photo_url = "http://www.jamkazam.com/images/bands/photos/#{self.id}.gif";
end
def logo_url
# TODO: move image path to config
@logo_url = "http://www.jamkazam.com/images/bands/logos/#{self.id}.gif";
end
end
end

View File

@ -3,7 +3,11 @@ module JamRuby
self.primary_key = 'id'
has_and_belongs_to_many :users, :class_name => "JamRuby::User"
# users
has_many :user_instruments
has_many :users, :through => :user_instruments, :class_name => "JamRuby::User"
# music sessions
has_and_belongs_to_many :music_sessions, :class_name => "JamRuby::MusicSession", :join_table => "genres_music_sessions"
end

View File

@ -2,27 +2,35 @@ module JamRuby
class User < ActiveRecord::Base
attr_accessible :name, :email, :password, :password_confirmation
attr_accessor :updating_password, :online
attr_accessor :updating_password, :online, :photo_url
self.primary_key = 'id'
# re-visit later (used for multiple table inheritance w/ Musician model)
# belongs_to :biz, :polymorphic => true
# connections (websocket-gateway)
has_many :connections, :class_name => "JamRuby::Connection"
# friend requests
has_many :friend_requests, :class_name => "JamRuby::FriendRequest"
# instruments
has_many :user_instruments
has_many :instruments, :through => :user_instruments, :class_name => "JamRuby::Instrument"
# bands
has_and_belongs_to_many :bands, :class_name => "JamRuby::Band"
# friends
has_many :friendships, :class_name => "JamRuby::Friendship", :foreign_key => "user_id"
has_many :friends, :through => :friendships, :class_name => "JamRuby::User"
has_many :inverse_friendships, :class_name => "JamRuby::Friendship", :foreign_key => "friend_id"
has_many :inverse_friends, :through => :inverse_friendships, :source => :user, :class_name => "JamRuby::User"
# music sessions
has_many :music_session_clients, :class_name => "JamRuby::MusicSessionClient"
has_many :created_music_sessions, :foreign_key => "user_id", :inverse_of => :user, :class_name => "JamRuby::MusicSession" # sessions *created* by the user
has_many :music_sessions, :through => :music_session_clients, :class_name => "JamRuby::MusicSession"
# invitations
has_many :received_invitations, :foreign_key => "receiver_id", :inverse_of => :receiver, :class_name => "JamRuby::Invitation"
has_many :sent_invitations, :foreign_key => "sender_id", :inverse_of => :sender, :class_name => "JamRuby::Invitation"
@ -46,6 +54,11 @@ module JamRuby
return @online
end
def photo_url
# TODO: move image path to config
@photo_url = "http://www.jamkazam.com/images/users/photos/#{self.id}.gif";
end
def should_validate_password?
updating_password || new_record?
end
@ -60,6 +73,24 @@ module JamRuby
return id
end
def self.save(params)
if params[:id].nil?
user = User.new()
else
user = User.find(params[:id])
end
@user = User.find(params[:id])
@user.email = params[:email]
@user.musician = params[:musician]
if @user.musician
@user.instruments = params[:instruments]
@user.bands = params[:bands]
end
@user.save
return user
end
private
def create_remember_token
self.remember_token = SecureRandom.urlsafe_base64

View File

@ -0,0 +1,10 @@
module JamRuby
class UserInstrument < ActiveRecord::Base
self.table_name = "users_instruments"
belongs_to :user
belongs_to :instrument
end
end