Skip to content

Instantly share code, notes, and snippets.

View uptownhr's full-sized avatar

James Lee uptownhr

View GitHub Profile
@uptownhr
uptownhr / gist:c0c5cbabb0e26e5bcea9
Created January 23, 2015 01:30
forme in sinatra ERB outputing to escaped string
<% form(@user, :action => '/user/update/' + @user.id.to_s, :method => 'PUT') do |f| %>
<%= partial 'users/form', :locals => { :f => f } %>
<% end %>
#output in string using sinatra ERB.
#attempted to follow, https://github.com/jeremyevans/forme#erb-support
#but not sure how to change the @out_buf
&lt;span class=&quot;label&quot;&gt;Accounts&lt;/span&gt;&lt;label class=&quot;option&quot;&gt;&lt;input checked=&quot;checked&quot; id=&quot;user_account_pks_1&quot; name=&quot;user[account_pks][]&quot; type=&quot;checkbox&quot; value=&quot;1&quot;/&gt; TestAccount&lt;/label&gt;&lt;label class=&quot;option&quot;&gt;&lt;input checked=&quot;checked&quot; id=&quot;user_account_pks_2&quot; name=&quot;user[account_pks][]&quot; type=&quot;checkbox&quot; value=&quot;2&quot;/&gt; new user name&lt;/label&gt;
@uptownhr
uptownhr / gist:33825b6b448eff0d25db
Created January 26, 2015 20:29
wrapping checkbox items with forme
#use tag_wrapper
<ul>
<%= f.input :accounts, :as=>:checkbox, :tag_wrapper => :li %>
</ul>
# output
<ul>
<span class="label">Accounts</span><li><label class="option"><input checked="checked" id="user_account_pks_1" name="user[account_pks][]" type="checkbox" value="1"> TestAccount</label></li><li><label class="option"><input checked="checked" id="user_account_pks_2" name="user[account_pks][]" type="checkbox" value="2"> new user name</label></li>
</ul>
add_hidden_tag do |tag|
p "testing"
if defined?(::Rack::Csrf) && (form = tag.form) && (env = form.opts[:env]) && tag.attr[:method].to_s.upcase == 'POST'
{::Rack::Csrf.field=>::Rack::Csrf.token(env)}
end
p "testing"
PP.pp tag
end
@uptownhr
uptownhr / gist:358d0723cb7137728780
Last active August 29, 2015 14:14
creating a new record using association pk plugin
params = {"user"=>{"name"=>"zxcv", "surname"=>"", "email"=>"[email protected]", "crypted_password"=>"asdfasdf", "role"=>"admin", "status"=>"active", "account_pks"=>["1"]}}
@user = User.new(params[:user])
###
error
PG::SyntaxError: ERROR: INSERT has more target columns than expressions
LINE 1: INSERT INTO "accounts_users" ("user_id", "account_id") VALUE...
###
User Model
@uptownhr
uptownhr / gist:b1c6aa46747db1a8c15d
Last active August 29, 2015 14:15
Sequel, ManyToMany Table with other fields

How should I be creating models to properly handle a many to many relation with batches_transactions and also be able to access the additional fields available in the batches_transactions tables. Should be modeling my tables differently?

Sequel.migration do
  up do
    create_table :transactions do
      primary_key :id
      String :status #new, #completed
@uptownhr
uptownhr / gist:7055f7ef988a4ec9f244
Created February 17, 2015 02:53
js array filter clone
File Edit Options Buffers Tools Javascript Help
var test =[{a:1},{a:2},{a:3}];
exist = test.filter( function(itme){
return itme.a == 3
})
console.log(exist) //outputs a:3
exist.a = 99;
console.log(test); //outputs a:1, a:2, a:3
trans_ids = transactions.all.inject({}) do |hash, trx|
if hash[trx.mid_id].nil?
hash[trx.mid_id] = []
end
hash[trx.mid_id].push trx.id
end
PP.pp trans_ids
@uptownhr
uptownhr / gist:a383f0a32ccb0ca2c69f
Created February 18, 2015 21:42
how does this not cause an error in react?
render: function() {
return (
<div className="commentBox">
<h1>Comments</h1>
<CommentList data={this.state.data} />
<CommentForm onCommentSubmit={this.handleCommentSubmit} />
</div>
);
$json = "{
rule_type: 'standard',
aggregate: {
action: 'sum',
column: 'amount'
},
trans_type: ['a','o','r'],
interval: 'monthly',
value: {
gt: 1000000
@uptownhr
uptownhr / gist:8a204648bf0f05fb8aae
Created May 1, 2015 17:36
unique index not working
Sequel.migration do
up do
create_table :locations do
primary_key :id
String :address
String :lat
String :long
DateTime :created_at
DateTime :updated_at
end