Skip to content

Instantly share code, notes, and snippets.

View SweeD's full-sized avatar

Markus Schwed SweeD

View GitHub Profile
require 'rspec/mocks'
class ClassForMocking
end
RSpec::Mocks::setup(ClassForMocking)
# 1. ================
# Could work (never tried)
Rails.application.routes.draw do
load 'routes/admin' # file includes just the routes
load 'routes/crm' # file includes just the routes
resources :customer
@SweeD
SweeD / get_posts_example
Created April 27, 2011 15:12
GET /posts response example
<posts>
<post>
<attr></attr>
<comments>
<comment> ... </comment>
...
</comments>
</post>
</posts>
@SweeD
SweeD / gist:948896
Created April 29, 2011 19:41
Ugly arrayify
class Object
def arrayify
[*self]
end
end
@SweeD
SweeD / new_trophy_route.rb
Created February 7, 2012 16:13
Routing with constraints
class NewTrohpyRoute
def self.matches?(request)
trophy_id = request.params[:trophy_id] # Not sure if you can get the params this way
return NewTrophy.where(:id => trophy_id).count > 1
end
end
@SweeD
SweeD / base_menu_view.js
Created November 22, 2012 11:49
EmberJS - Add a computed property via method
App.BaseMenuView = Ember.View.extend{
statesForActiveCheck: [],
init: function(){
this._super()
this.get('statesForActiveCheck').forEach(this.addActiveCheckMethod, this)
},
addActiveCheckMethod: function(statePart){
functionName = statePart.replace('.', '_').camelize() + 'Active'; // the function name for 'account.settings' should be 'accountSettingsActive'
@SweeD
SweeD / breadcrumb.handlebars
Created December 7, 2012 07:53
EmberJS - Dynamic breadcrumb rendering (with action as variable)
<!---- Version 1 with #each -->
<ul class="breadcrumb">
{{#each view.breadcrumbElements}}
<li><a {{action lastObject href=true}}>{{firstObject}}</a><span class="divider">/</span></li>
{{/each}}
</ul>
<!--- Version 2 with custom helper -->
<ul class="breadcrumb">
{{renderBreadcrumb view.breadcrumb}}
@SweeD
SweeD / store.js.coffee
Created January 16, 2013 14:17
Sad try to to use a DS.Model and DS.Store up and running.
When I try to find a model in the console, i get an error.
MyApp.User.find(98)
> TypeError: Object Ember has no method 'merge'
@SweeD
SweeD / models.coffee
Created January 30, 2013 09:04
I try to load hasMany associations embedded...what am I doing wrong?!
App.User = DS.Model.extend
#...
addresses: DS.hasMany(GleichklangWeb.Address, { embedded: true })
App.Address = DS.Model.extend
#...
user: DS.belongsTo(GleichklangWeb.User)
App.Router.map ->
@resource 'portal', ->
@route 'dashboard'
@resource 'developers', ->
@resource 'messages', ->
@route 'inbox'
@route 'hidden'
@resource 'sysops', ->