You won??™t migrate
anything in it at this stage, but sometimes Rails makes funny things happen when no
database is available.
After you??™ve created and configured the database, you need to create some models and
migrations. As I mentioned in the chapter introduction, the actual model for LibLib isn??™t that
complicated:
jruby script/generate model Authentication
jruby script/generate model Librarian
jruby script/generate model Borrower
jruby script/generate model BorrowedBook
Now, the Librarian, Borrower, and BorrowedBook models are obvious in what they represent,
but Authentication isn??™t as easy. Simply put, Authentication contains the username and password
of either a Borrower or a Librarian, or both. So, it??™s the object that??™s used for authentication,
and you can share this authentication between a Borrower and a Librarian if you want.
The migration for Authentication is more or less what you would expect:
class CreateAuthentications < ActiveRecord::Migration
class Authentication < ActiveRecord::Base; end
def self.up
create_table :authentications do |t|
t.column :username, :string
t.column :password, :string
end
Authentication.create :username => 'admin', :password => 'admin'
end
def self.down
drop_table :authentications
end
end
You need to bootstrap by creating a simple authentication for admin. The actual database
table is just two strings and the regular Rails ID.
CHAPTER 14 ?– THE LIBLIB RAILS APPLICATION 254
The second migration is CreateLibrarian, which only is a list of Authentications that
have access to administrate the library:
class CreateLibrarians < ActiveRecord::Migration
class Authentication < ActiveRecord::Base; end
class Librarian < ActiveRecord::Base; end
def self.
Pages:
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379