File tree Expand file tree Collapse file tree 1 file changed +16
-0
lines changed Expand file tree Collapse file tree 1 file changed +16
-0
lines changed Original file line number Diff line number Diff line change @@ -114,6 +114,22 @@ Modifying our model example:
114
114
This would allow you to specify a custom value for per_page just for posts, or
115
115
to fall back to your default value if not specified.
116
116
117
+ === 4. Suppressing Exceptions Conditionally
118
+
119
+ Raising exceptions for missing settings helps highlight configuration problems. However, in a
120
+ Rails app it may make sense to suppress this in production and return nil for missing settings.
121
+ While it's useful to stop and highlight an error in development or test environments, this is
122
+ often not the right answer for production.
123
+
124
+ class Settings < Settingslogic
125
+ source "#{Rails.root}/config/application.yml"
126
+ namespace Rails.env
127
+ suppress_errors Rails.env.production?
128
+ end
129
+
130
+ >> Settings.non_existent_key
131
+ => nil
132
+
117
133
== Note on Sinatra / Capistrano / Vlad
118
134
119
135
Each of these frameworks uses a +set+ convention for settings, which actually defines methods
You can’t perform that action at this time.
0 commit comments