This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Factory :run do | |
# [...] | |
distances {|distances| [distances.association(:distance)]} | |
# [...] | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
distance_a = Factory.create(:distance) # only created to pass the Run model's validations | |
distance_b = Factory.create(:distance) | |
Factory.create(:run, :distances=>[distance_a, distance_b]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Factory.create(:run) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html><body><div style='width:7.5cm;height:4.5cm;border:1px dashed black;margin-bottom:1cm;margin-right:1cm;float:left'>Nerd Level: 3<br/>Which one is the fastest sorting algorithm? <br/>a1: Selection Sort<br/>a2: Quick Sort<br/>a3: Bubble Sort<br/>a4: All the same<br/></div><div style='width:7.5cm;height:4.5cm;border:1px dashed black;margin-bottom:1cm;1cm;float:left;'><p style='margin:0px auto'>a2</p></div><br style='clear:left' /><div style='width:7.5cm;height:4.5cm;border:1px dashed black;margin-bottom:1cm;margin-right:1cm;float:left'>Nerd Level: 2<br/>What's the average run time of a search in a Binary Search Tree? <br/>a1: O(n)<br/>a2: O(n log n)<br/>a3: O(log n)<br/>a4: O(1)<br/></div><div style='width:7.5cm;height:4.5cm;border:1px dashed black;margin-bottom:1cm;1cm;float:left;'><p style='margin:0px auto'>a3</p></div><br style='clear:left' /><div style='width:7.5cm;height:4.5cm;border:1px dashed black;margin-bottom:1cm;margin-right:1cm;float:left'>Nerd Level: 2<br/>How to call the last command after sub |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<head> | |
</head> | |
<body> | |
<div style="width:7.5cm;height:5.5cm;border:1px dashed black;margin-bottom:1cm;margin-right:1cm;float:left"></div> | |
<div style="width:7.5cm;height:5.5cm;border:1px dashed black;margin-bottom:1cm;1cm;float:left;"></div> | |
<br style="clear:left" /> | |
</body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"type": "object", | |
"title": "user", | |
"description": "a user", | |
"properties": { | |
"id": { | |
"type": "string", | |
"description": "The User Id", | |
"identity": true, | |
"required": true, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Api::UsersController < ApiController | |
def show | |
respond_with(object_as_json(User.find_by_slug(params[:id]))) | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# app/views/posts/index.rabl | |
collection @posts | |
attributes :id, :title, :subject | |
child(:user) { attributes :full_name } | |
node(:read) { |post| post.read_by?(@user) } | |
The result of this is a JSON (or XML) looking like this: | |
[{ post : | |
{ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# app/app.rb | |
get "/posts", :provides => [:json, :xml] do | |
@user = current_user | |
@posts = Post.order("id DESC") | |
render "posts/index" | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
render :json => { :success => true, :user => @user.as_json(:only => [:email]) } |