Improve channel, user and api_key models with basic scopes, correct references and protect attributes.

Simplify channels & user controllers and models, moving code to the models.
Remove catch-all route and ensure all actions are specified, fixing url paths.
Change clone to dup in feed_controller as using clone seems to affect the cloned object (problem only in ruby 1.9.3?)
This commit is contained in:
Alan Bradburne
2012-02-09 23:42:16 +00:00
parent bfd5b29a9a
commit 4f0354303f
21 changed files with 198 additions and 172 deletions

14
lib/key_utilities.rb Normal file
View File

@ -0,0 +1,14 @@
module KeyUtilities
# generates a database unique api key
def generate_api_key(size = 16)
alphanumerics = ('0'..'9').to_a + ('A'..'Z').to_a
k = (0..size).map {alphanumerics[Kernel.rand(36)]}.join
# if key exists in database, regenerate key
k = generate_api_key if ApiKey.find_by_api_key(k)
# output the key
k
end
end