views:

44

answers:

2

For each organization , using my application need to set a ' maximum license count' ,for.example ,100.Then,one user in that organization login to the application the 'used count' become 1.If login another user, 'used count' increment to become 2.In that way, if try to access the application by many users, and 'used count' become 100,the 'used count' become equal to the 'maximum license count'.Then , if any one try to access the application should show a message 'License count exceeded' and will not allow the user to login.

+1  A: 

You can do it in follwing ways

1] Create a field in database say max_count

2] increment the count when some one sign-up (i doubt it you want for login)

3] when some one try to sign-up validate it using follwing method in model

   def validate
     if self.nil && self.max_count >= 100
       self.errors.add :base, 'License count exceeded.'
     end
   end
Salil
+1  A: 

You're going to have to define the license count requirements better to fully answer the question, but here are some ideas to consider:

  • If the license count is for registered users, simply check User.find(:all).length is less than n.
  • If the license count is for users who have logged in but have not logged out, add a boolean "logged_in" field to the user and do as above, but finding all the logged_in users. Set the field at login, clear it at logout.
  • If the license count is for active users, count the number of active entries in the sessions table.
John Franklin