Skip to content

Instantly share code, notes, and snippets.

View bhserna's full-sized avatar

Benito Serna bhserna

View GitHub Profile
@bhserna
bhserna / index.html.erb
Created June 3, 2012 19:12
Your api in your views
<%= content_tag "div", class: "milestones",
data: {
milestones: render(template: "api/v1/milestones/index.json")
} do %>
<%= javascript_tag do %>
jQuery(function(){
App.init();
});
<% end %>
@bhserna
bhserna / routes.rb
Created July 7, 2012 22:22
User-centric Routing with Devise and Rails
authenticated do
root :to => 'users#home'
end
root :to => 'pages#home'
#= require "commentator_templates"
#= require "commentator_poster"
#= require "commentator_params"
class window.Commentator
constructor: (args) ->
params = new CommentatorParams(args)
@el = params.el()
@url = params.url()
@bhserna
bhserna / controllers.rb
Created November 27, 2012 02:06
Factory method using convention and ruby
class ApplicationController < ActionController::Base
# other stuff ..
def notify(*args)
Notifications::Notifier.new.notify(*args)
end
end
class CommentsController < ApplicationController
@bhserna
bhserna / where_is_the_app.markdown
Last active December 10, 2015 14:38
This are different examples to do the same thing, "mark a notification as read", and the pros and cons that I see in each example

Where is the app?

This are different examples of doing the same thing, "mark a notification as read", and the pros and cons that I see in each example

1. - Logic in the model

  • The user clicks the notification link
  • The system POSTs to the action "notifications/:id/mark_as_read"
  • The controller calls the method Notification#mark_as_read
  • The model updates the attribute "read" saves the Notification record
<script type="text/x-handlebars" data-template-name="tab">
<ul id="customer-tab">
{{#each tabItem in tabItems}}
<li>
<h3>
{{tabItem.food.name}}
<span><a href="#" {{action "removeFood" tabItem.food}}>x</a></span>
<span>${{money tabItem.total}}</span>
</h3>
</li>
#= require application
#= require_self
#= require fixtures
#= require_tree .
document.write('<div id="ember-testing-container"><div id="ember-testing"></div></div>')
document.write('<style>#ember-testing-container { position: absolute; background: white; bottom: 0; right: 0; width: 640px; height: 384px; overflow: auto; z-index: 9999; border: 1px solid #ccc; } #ember-testing { zoom: 50%; }</style>')
App.rootElement = '#ember-testing'
App.setupForTesting()
@bhserna
bhserna / pendingreview.html.erb
Last active December 26, 2015 09:09
emberjs vs my frontend hacks -- sprinkles
<script>
new PendingReviewForm("#trip_<%= trip.id %>", "#pending_review_<%= pending_review.id %>")
</script>
@bhserna
bhserna / menu.hbs
Created October 23, 2013 22:20
emberjs vs frontend hacks --- emberjs
{{#if currentUser.questionsToAnswer}}
<span class="navbar-menu__badge">
{{currentUser.questionsToAnswerCount}}
</span>
{{/if}}
require 'json'
require 'yaml'
all = [{:id=>1, :label=>"floral", :color=>"#F5F058", :parent_id=>nil, :label_es=>"floral", :open=>1, :zoomed=>1, :selected=>1, :flavor_type=>"flavor", :positive=>1}, {:id=>2, :label=>"fruit", :color=>"#AA274E", :parent_id=>nil, :label_es=>"frutal", :open=>1, :zoomed=>1, :selected=>1, :flavor_type=>"flavor", :positive=>1}, {:id=>3, :label=>"chocolate", :color=>"#6F5740", :parent_id=>nil, :label_es=>"chocolate", :open=>1, :zoomed=>1, :selected=>1, :flavor_type=>"flavor", :positive=>1}, {:id=>4, :label=>"sweet", :color=>"#FAF8A9", :parent_id=>nil, :label_es=>"dulce", :open=>1, :zoomed=>1, :selected=>1, :flavor_type=>"flavor", :positive=>1}, {:id=>5, :label=>"nut", :color=>"#F38546", :parent_id=>nil, :label_es=>"nuez", :open=>1, :zoomed=>1, :selected=>1, :flavor_type=>"flavor", :positive=>1}, {:id=>6, :label=>"grain/cereal", :color=>"#AB9566", :parent_id=>nil, :label_es=>"granos/cereal", :open=>1, :zoomed=>1, :selected=>1, :flavor_type=>"flavor", :positive=>1}, {:id=>7, :label=>"roa