Skip to content

Instantly share code, notes, and snippets.

require 'ostruct'
class MyForm < OpenStruct
include ActiveModel::Validations
include ActiveModel::Conversion
extend ActiveModel::Naming
validates :name, :presence => true
def initialize(*args)
super
@jlebrech
jlebrech / edit.html.erb
Last active August 29, 2015 13:56
RealForm
<% @my_form.render do |f| # custom form %>
<div class="firstname"><%= f.firstname # maybe options are possible here %></div>
<div class="text"><%= f.text %></div>
<% end %>
<%= @my_form.render # no customization %>
@jlebrech
jlebrech / components.xml
Created June 3, 2014 16:14
Just a mashup of a site layout using simple semantics
<main>
<nav>
<link to="">somewhere</link>
link to="">somewhere</link>
link to="">somewhere</link>
</nav>
<section type="blog">
<post author="" date="">
Lorem ipsum
</post>
<link rel="import" href="../components/polymer/polymer.html">
<polymer-element name="my-element">
<template>
<style>
#core_scaffold {
position: absolute;
top: 0px;
right: 0px;
results = []
for (i in res.guests){
model = {
name: res.guests[i].name
};
Object.defineProperties(model, {
'reversename': {
@jlebrech
jlebrech / a.stache
Created October 14, 2014 16:44
Can bootstrap
<ui-panel>
<div class="panel-heading">
Title here
</div>
<div class="panel-body" style="height:200px">
....
</div>
<div class="panel-footer clearfix">
Footer
</div>
<?php $contain = array(
'Module' => array(
'Question' => array(
'Answer',
'order' => 'RAND()',
'limit' => 15
),
'order' => array('order','name')
)
);
def update
@company = Company.find(params[:id])
# @company.user = current_user
@company.projects.each do |p|
if p.user.nil?
p.user = current_user
end
end
<div class="root-box">
<h1><%= link_to 'Companies', companies_path %></h1>
<div class="company-box">
<h1><%= h @company.name %></h1>
<% if !@company.user.nil? %>
<h2><%= h @company.user.username %></h2>
<% end %>
<%= link_to 'Edit', edit_company_path(@company) %>
<?php
/**
*
* PHP versions 4 and 5
*
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
* Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
*
* Licensed under The MIT License
* Redistributions of files must retain the above copyright notice.