forked from dingbat/nsrails
-
Notifications
You must be signed in to change notification settings - Fork 0
/
app_delegate.rb
48 lines (39 loc) · 1.8 KB
/
app_delegate.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
class AppDelegate
def application(application, didFinishLaunchingWithOptions:launchOptions)
@window = UIWindow.alloc.initWithFrame(UIScreen.mainScreen.bounds)
NSRConfig.defaultConfig.appURL = "http://nsrails.com"
# For testing on local server:
# NSRConfig.defaultConfig.appURL = "http://localhost:3000"
NSRConfig.defaultConfig.appUsername = "NSRails"
NSRConfig.defaultConfig.appPassword = "iphone"
# Autoinflection will underscore and camelize ("created_at" from Rails will look for "createdAt")
# We don't want this since we're in Ruby and our properties are underscored anyway!
NSRConfig.defaultConfig.autoinflectsPropertyNames = false
posts = PostsViewController.alloc.initWithStyle(UITableViewStyleGrouped)
nav = UINavigationController.alloc.initWithRootViewController(posts)
@window.rootViewController = nav
@window.makeKeyAndVisible
true
end
def self.alertForError(e)
errorString = ""
# Get the dictionary of validation errors, if present
validationErrors = e.userInfo[NSRValidationErrorsKey]
if (validationErrors)
# Iterate through each failed property (keys)
validationErrors.each do |failed_property, reasons|
# Iterate through each reason the property failed
reasons.each do |reason|
errorString += "#{failed_property.capitalizedString} #{reason}. " #=> "Name can't be blank."
end
end
else
if (e.domain == NSRRemoteErrorDomain)
errorString = "Something went wrong! Please try again later or contact us if this error continues."
else
errorString = "There was an error connecting to the server."
end
end
UIAlertView.alloc.initWithTitle("Error", message:errorString, delegate:nil, cancelButtonTitle:"OK", otherButtonTitles:nil).show
end
end