# lib/custom_logger.rb | |
class CustomLogger < Logger | |
def format_message(severity, timestamp, progname, msg) | |
"#{timestamp.to_formatted_s(:db)} #{severity} #{msg}\n" | |
end | |
end | |
logfile = File.open("#{Rails.root}/log/custom.log", 'a') # create log file | |
logfile.sync = true # automatically flushes data to file | |
CUSTOM_LOGGER = CustomLogger.new(logfile) # constant accessible anywhere |
<!-- Temporary breakpoint debugger --> | |
<span class="sm:hidden">XS</span> | |
<span class="hidden sm:inline md:hidden">SM</span> | |
<span class="hidden md:inline lg:hidden">MD</span> | |
<span class="hidden lg:inline xl:hidden">LG</span> | |
<span class="hidden xl:inline">XL</span> | |
<!-- / Temporary breakpoint debugger --> |
<%= turbo_frame_tag "new_message", target: "_top" do %> | |
<%= form_with(model: [@message.room, @message], data: { controller: "reset-form", action: "turbo:submit-end->reset-form#reset" }) do |form| %> | |
<%= form.text_field :content, autocomplete: 'off', placeholder: 'Write your message...' %> | |
<%= button_tag(type: :submit) do %> | |
<i class="fa fa-paper-plane" aria-hidden="true"></i> | |
<% end %> | |
<%= form.submit "Send", data: {disable_with: false} %> | |
<% end %> | |
<% end %> |
// DISCLAIMER : You can now probably use `data-turbo-action="advance"` on your frame to perform what this controller is aiming to do | |
// https://turbo.hotwired.dev/handbook/frames#promoting-a-frame-navigation-to-a-page-visit | |
// Note that you probably want to disable turbo cache as well for those page to make popstate work properly | |
import { navigator } from '@hotwired/turbo' | |
import { Controller } from '@hotwired/stimulus' | |
import { useMutation } from 'stimulus-use' | |
export default class extends Controller { | |
connect (): void { |
<div class="form-group"> | |
<%= form.label :type, "Type", class: "font-weight-bold" %> | |
<%= form.select :type, ['TextQuestion', 'UrlQuestion'], { include_blank: true }, { class: "form-control", data: { action: "input->toggle#changed", target: "toggle.select" } } %> | |
</div> | |
<div class="form-group"> | |
<%= form.label :name, "Name", class: "font-weight-bold" %> | |
<%= form.text_field :name, class: "form-control" %> | |
</div> | |
<div class="form-group" data-target="toggle.element" data-values="UrlQuestion"> | |
<%= form.label :url, "URL", class: "font-weight-bold" %> |
require 'rails_helper' | |
RSpec.describe External::Provider::Base do | |
let(:subject) { described_class.new SecureRandom.hex } | |
describe '#for' do | |
it 'returns Facebook provider' do | |
class_instance = described_class.for :facebook | |
expect(class_instance).to eq(External::Provider::Facebook) | |
end |
This is another piece of code I've extrapolated from a Ruby on Rails project I'm currently working on. The code implmenets social login with a RoR API-based application, targeted at API clients.
The setup does not involve any browser-redirects or sessions as you would have to use working with Omniauth.
Instead, what it does is takes an access_token generated on client-side SDKs, retireves user info from the access token
and creates a new user and Identity
in the database.
This setup works with native applications as described in the Google iOS Sign In Docs (see Authenticating with a backend server)
This is just some code I recently used in my development application in order to add token-based authentication for my api-only rails app. The api-client was to be consumed by a mobile application, so I needed an authentication solution that would keep the user logged in indefinetly and the only way to do this was either using refresh tokens or sliding sessions.
I also needed a way to both blacklist and whitelist tokens based on a unique identifier (jti)
Before trying it out DIY, I considered using: