Skip to content

Instantly share code, notes, and snippets.

View dummycode's full-sized avatar

Henry Harris dummycode

View GitHub Profile
<% @post.sources.each do |source| %>
<%= render("posts/fields/source", source: source) %>
<% end %>
<%= add_source_button %>
def add_source_button
fields = render('posts/fields/source', source: '', id: :new_source_field)
button_tag "Add Source", class: "add-fields", data: { id: :new_source_field, fields: fields }
end
$(function () {
$('form').on('click', '.add-fields', function(event) {
event.preventDefault()
const time = new Date().getTime()
const regexp = new RegExp($(this).data('id'), 'g')
$(this).before(
$(this).data('fields').replace(regexp, time),
)
})
})
$(function () {
$('form').on('click', '.remove-section', function(event) {
event.preventDefault()
const removalTarget = $(this).data('target')
$(this).closest(removalTarget).remove()
})
})
DEFAULT_PARAMS = { :sources => [] }
def post_params
DEFAULT_PARAMS.merge(
params.require(:post).permit(
:title,
:body,
sources: [],
)
)
end
post[sources][][title]: "Example One"
post[sources][][url]: "https://one.example.com"
post[sources][][title]: "Example Two"
post[sources][][url]: "https://two.example.com"
<%= text_field_tag 'post[sources][][title]', item[‘title’] %>
<%= text_field_tag 'post[sources][][url]', item[‘url’], placeholder: 'https://example.com' %>
DEFAULT_PARAMS = { :sources => [] }
def post_params
DEFAULT_PARAMS.merge(
params.require(:post).permit(
:title,
:body,
sources: [
:title,
:url,
validate :all_sources_have_title_and_url
def all_sources_have_title_and_url
if sources.any? {|source| !source['title'].present? || !source['url'].present? }
errors.add(:base, 'All sources must have a title and url')
end
end
WIDTH=32;
DEPTH=8192;
ADDRESS_RADIX=HEX;
DATA_RADIX=HEX;
CONTENT BEGIN
[00000000..0000000f] : DEAD;
-- @ 0x00000040 : XOR ZERO,ZERO,ZERO
00000010 : 00000011;
-- @ 0x00000044 : LW SP,STACKTOPVAL(ZERO)
00000011 : a0c001a4;