While you??™re
at it, you should probably use the same technique to customize the library ID for each Rails
application. Add this to the environment.rb:
$CURRENT_LIBRARY_ID = (ENV["LIBLIB_ID"] || 82).to_i
Because the ID should be numeric for your legacy integration code to work correctly, you
need to call to_i on the resulting value, just to make sure.
With all this in place, you can always change the behavior of the application before starting
it. Not only can you do it manually, but it??™s easy to add this information to the start script
that you??™ll be using to invoke the Rails application (because you still have all those Java JAR
dependencies that need to be on the CLASSPATH when starting).
Creating the Model
As we talked about earlier, there isn??™t much to the model, so I??™ll just present it without adornment
here. Here??™s the Authentication model:
class Authentication < ActiveRecord::Base
validates_presence_of :username, :password
validates_uniqueness_of :username
end
It makes sure that both username and password are provided, and also that you don??™t provide
a username that??™s already in use. Other than that, it??™s your basic garden-variety model.
The Borrower and Librarian models are in the same vein:
class Librarian < ActiveRecord::Base
belongs_to :authentication
CHAPTER 14 ?– THE LIBLIB RAILS APPLICATION 257
def is_borrower?
Borrower.find_by_authentication_id(self.authentication.id)
end
end
class Borrower < ActiveRecord::Base
belongs_to :authentication
has_many :borrowed_books
def is_librarian?
Librarian.
Pages:
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383