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
//// For Rails projects with rails-ujs Check official guide: https://guides.rubyonrails.org/working_with_javascript_in_rails.html#rails-ujs-event-handlers | |
// In xxx.html.erb, we can write | |
// <%= link_to 'xxx', url, remote: true, data: { type: :json, disalbe_with: "...", confirm: "ok?" }, class: 'js-remote-link' %> | |
$(document).on("ajax:success", ".js-remote-link", function(e) { | |
var data = event.detail[0] | |
var status = event.detail[1] | |
var xhr = event.detail[2] | |
console.log(data) // {message: "SUCCESS ✓"} | |
console.log(status) // OK |
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
# lib/action_text_parser.rb | |
# require 'action_text_parser' in application.rb | |
class ActionTextParser | |
def self.run(action_text_record) | |
html = action_text_record.body.to_html | |
nodes = Nokogiri::HTML::DocumentFragment.parse html | |
nodes = self.parse_attachments(nodes) | |
nodes = self.parse_code(nodes) | |
nodes.to_html | |
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
import TwCitySelector from 'tw-city-selector/dist/tw-city-selector.min.js' | |
import { Controller } from "@hotwired/stimulus" | |
export default class extends Controller { | |
connect() { | |
let controller = this | |
new TwCitySelector({ | |
el: '.city-selector-set', | |
elCounty: '.county', | |
elDistrict: '.district', |
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
<% # I have a slide contains 6 images. %> | |
<% # And also I have different versions of them based on media queries. %> | |
<% # We can load the 2nd to 6th images asynchronously. %> | |
<% (2..6).each do |num| %> | |
<div data-controller="preload-img" data-preload-img-src-value='<%= asset_path("slides/pc/#{num}.jpg") %>' data-preload-img-media-value="(min-width: 992px)"></div> | |
<div data-controller="preload-img" data-preload-img-src-value='<%= asset_path("slides/mobile/#{num}.jpg") %>' data-preload-img-media-value="(max-width: 991px)"></div> | |
<% 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
module WebI18nLocale | |
extend ActiveSupport::Concern | |
included do | |
prepend_before_action :digest_locale_params | |
before_action :set_locale | |
helper_method :set_locale_path | |
end | |
private |
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/views/hello.html --> | |
<h1>Hello!</h1> |
OlderNewer