You are currently browsing the category archive for the ‘Rails’ category.
If your environments/*.rb look like a repetitive mess, its time to get a config.yml!
- overview of your configuration
- dry code
- (optional) not check in all the passwords/keys of your app (only check in config.example.yml), great for open-source apps
- Can be loaded without loading the environment (e.g. small rake tasks)
# lib/cfg.rb
CFG = YAML.load(ERB.new(
File.read("config/config.yml")
).result)[Rails.env].with_indifferent_access
# config/application.rb
require "cfg"
# config/config.yml
common: &common
api:
airbrake_key: xxx
google_analytics_key: yyy
admin_email: admin@example.com
test:
<<: *common
host: 'localhost'
development:
<<: *common
host: 'localhost'
production:
<<: *common
host: 'fuu.bar'
# config/application.rb
config.action_mailer.default_url_options = {:host => CFG[:host]}
Need your bookmarks on the go !?
the source is at https://github.com/grosser/mymarks, happy forking
Problem:
Lots of stuff does not need any translation, so we simply leave it untranslated (e.g. firstname shows as Firstname). But this leaves ugly “missing translation” spans in out html.
Instead of entering senseless translations for everything thats missing, we simply deactivate the tooltips in production, while also avoiding raising/rescuing theses MissingTranslation errors to improve performance(rescue/raise is not cheap).
Code:
If you want to run 1 big/slow test file, use Parallel-Split-Test, it splits it into multiple chunks and then runs them in parallel.
PS: If you have lots of tests you should take a look at Parallel-Tests, which runs multiple files in parallel.
This became necessary because in our current project: spec runtime=3h (without integration) / slowest file=5 minutes. Now this time is only 1/3rd.
No need to check in normal code, just do everything as usual and this interceptor will prevent you from spamming people who do not want any emails.
Its not perfect(missing bc/bcc filters but if should be fine for 90% of cases)
#config/initializers/blacklisted_emails.rb
class MailInterceptor
def self.delivering_email(message)
if User.where(:email => message.to, :receive_emails => false).any?
message.perform_deliveries = false
end
end
end
Mail.register_interceptor(MailInterceptor)
