This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# app/controllers/application_controller.rb | |
class ApplicationController < ActionController::Base | |
def append_info_to_payload(payload) | |
super | |
payload[:remote_ip] = request.remote_ip | |
end | |
end | |
# config/environments/<your env>.rb | |
Rails.application.configure do |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fields = %w(foo bar baz) | |
fields.each_with_object({}) do |field, memo| | |
memo[field] = rand(1000) | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
float = 123.45678 | |
"%.4f" % float | |
# => "123.4568" | |
# or you can write it in a little bit different way | |
sprintf "%.4f", float | |
# => "123.4568" |