Requirements:
If you're on OSX you're probably best off using Homebrew to install this stuff:
$ brew install node mongodb
Usage:
| // articles per page | |
| var limit = 10; | |
| // pagination middleware function sets some | |
| // local view variables that any view can use | |
| function pagination(req, res, next) { | |
| var page = parseInt(req.params.page) || 1, | |
| num = page * limit; | |
| db.articles.count(function(err, total) { | |
| res.local("total", total); |
| var mongoose = require('mongoose'); | |
| mongoose.connect('localhost/test'); | |
| var Schema = mongoose.Schema; | |
| var AlbumSchema = new Schema({ | |
| artist: { type: Schema.Types.ObjectId, ref: 'Artist' }, | |
| name: String, | |
| year: Number, |
| <!DOCTYPE html> | |
| <meta charset=utf-8> | |
| <meta name=viewport content="width=device-width, initial-scale=1, maximum-scale=1"> | |
| <meta name=apple-mobile-web-app-capable content=yes> | |
| <meta name=apple-mobile-web-app-status-bar-style content=black> | |
| <title>Test fullscreen</title> | |
| <style> | |
| html, body { | |
| margin: 0; | |
| padding: 0; |
| // add child view | |
| UIViewController* controller = [self.storyboard instantiateViewControllerWithIdentifier:@"test"]; | |
| [self addChildViewController:controller]; | |
| controller.view.frame = CGRectMake(0, 44, 320, 320); | |
| [self.view addSubview:controller.view]; | |
| [controller didMoveToParentViewController:self]; | |
| // remove child view | |
| UIViewController *vc = [self.childViewControllers lastObject]; | |
| [vc willMoveToParentViewController:nil]; |
| #import <Contacts/Contacts.h> | |
| @implementation ContactsScan | |
| - (void) contactScan | |
| { | |
| if ([CNContactStore class]) { | |
| //ios9 or later | |
| CNEntityType entityType = CNEntityTypeContacts; | |
| if( [CNContactStore authorizationStatusForEntityType:entityType] == CNAuthorizationStatusNotDetermined) |
An application I'm working on has two different types of Devise users, but I want both types of users to be able to use the same sign in form. Devise doesn't make this easy.
You could argue that I really should have a single user type with a role attribute, but the app is far enough along that I don't want to change that early design decision. It could be changed later if more pain points are discovered.
You could also argue that I shouldn't use Devise, but it's still the de facto authentication standard for Rails applications.
In this example, you can sign in as either a User or an AdminUser. This application only has two types of user, but this example could be extended to support any number of them more gracefully.