I would like to access the current user's albums by using the primary keys in the Schema below. I have User, Band, And Album models as follows...
class User < ActiveRecord::Base
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable
has_many :bands
end
class Band < ActiveRecord::Base
has_many :albums
has_many :users
end
class Album < ActiveRecord::Base
belongs_to :band
end
Schema as follows...
create_table "albums", force: true do |t|
t.string "name"
t.string "releaseDate"
t.string "artWorkUrl"
t.integer "band_id"
t.datetime "created_at"
t.datetime "updated_at"
end
create_table "bands", force: true do |t|
t.string "name"
t.datetime "created_at"
t.datetime "updated_at"
t.integer "user_id"
end
create_table "users", force: true do |t|
t.string "email", default: "", null: false
t.string "encrypted_password", default: "", null: false
t.string "reset_password_token"
t.datetime "reset_password_sent_at"
t.datetime "remember_created_at"
t.integer "sign_in_count", default: 0, null: false
t.datetime "current_sign_in_at"
t.datetime "last_sign_in_at"
t.string "current_sign_in_ip"
t.string "last_sign_in_ip"
t.datetime "created_at"
t.datetime "updated_at"
end
and am trying to use the following method in the Albums controller...
def albums
@albums = current_user.bands.albums
end
Sorry, i'm sure this is a noob question. I know this should be a simple primary key access through the user --> bands --> albums, using user_id and band_id but have been unable to populate the current users albums through bands. Any insight in much appreciated.