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
# Given there is a section object and I would like to use trix editor for adding text to the content attribute | |
# id: is required to tie trix-editor(below to to the hidden input | |
# name: is required so that you can find it via params in the controller in this case params["trix-editor_section_#{section.id}"] | |
# content: is for inserting any content that already existed in the content attribute | |
%input{id: "#{dom_id(section, 'trix-editor')}", name: "#{dom_id(section, 'trix-editor')}", content: "#{section.content}", type: :hidden} | |
%trix-editor{input: "#{dom_id(section, 'trix-editor')}"} |
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
# Code for processing icheck checkboxes | |
# with slight modification it can be used with normal checkboxes as well | |
# Check or uncheck all checkboxes | |
# | |
$('#checkAll').on 'ifChecked ifUnchecked', (event) -> | |
$checkboxes = $(this).closest('form').find(':checkbox') | |
if event.type == 'ifChecked' | |
$checkboxes.prop 'checked', true |
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
# Disable links with a class that ends with `_export_action` | |
# Example data-action='event_export_action' or data-action='room_export_action' | |
$(document).on 'click', "a[data-action$='_export_action']", -> | |
$this = $(this) | |
$label = $this.text | |
$this.attr('disabled', true).html('Working...') | |
# not necessary if page refreshes but just in case using with ajax | |
$this.attr('disabled', false).html($label) |
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
# spec/support/main_app.rb | |
module MainAppRoute | |
def main_app | |
Rails.application.class.routes.url_helpers | |
end | |
end | |
# In spec/rails_helper | |
RSpec.config do |config| | |
config.include MainAppRoute |
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
ActiveRecord::ConnectionAdapters::Column.value_to_boolean(value) | |
# Values for true: | |
# 1, "1", "t", "T", "true", "TRUE", true, "on", "ON" | |
# Values for false: | |
# 0, "0", "n", "N", "false", "FALSE", false, "off", "OFF" |
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
# scan for email addresses | |
text-variable.scan(/\b[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,}\b/i) | |
=> ['[email protected]', 'user2@domain'] | |
# Verify email addresses | |
a = Mail::Address.new('Foo Bar <[email protected]>') | |
a.address | |
=> "[email protected]" |
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
# Where data is a hash of predefined keys | |
# This example also shows at the end another hash inside of data | |
params.permit( | |
:date_range, | |
:email, | |
:enabled, | |
:id, | |
:limit, | |
:match, | |
:send_day, |
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
# iCheck helper methods | |
def check_checkbox(attribute=:name, value) | |
evaluate_script "$(\":checkbox[#{attribute}='#{value}']\").prop('checked', true).iCheck('update');" | |
end | |
def uncheck_checkbox(attribute=:name, value) | |
evaluate_script "$(\":checkbox[#{attribute}='#{value}']\").prop('checked', false).iCheck('update');" | |
end | |
# above can be refactored_to |
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
# In the rails controller something like: | |
def _params | |
params.permit(:param1, :param2).tap do |whitelisted| | |
# because submitting objects is optional | |
(whitelisted[:objects] = params[:objects]) if params[:objects] | |
end | |
end | |
# summary_params['objects'] => {'object.id' => 'boolean-valu'} |
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
Pre reqs: | |
I installed these using homebrew | |
* nodejs | |
* yarn | |
Create an application directory manually | |
$ mkdir app_name |
OlderNewer