Created
July 12, 2013 18:22
-
-
Save chintanparikh/5986633 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
%pre{data: {update_path: new_content_path(@endpoint.id, content.id) } } | |
%code.prettyprint~ JSON.pretty_generate(JSON[content.content]) |
This file contains hidden or 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
# Place all the behaviors and hooks related to the matching controller here. | |
# All this logic will automatically be available in application.js. | |
# You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/ | |
$ -> | |
prettyPrint() | |
setInterval (-> | |
first = $('pre')[0] | |
if typeof first == 'undefined' | |
first = $("#content") | |
url = $(first).data('update-path') | |
$.ajax | |
url: url | |
type: "GET" | |
success: (response) -> | |
content = response.content | |
console.log(response.content) | |
if content != null | |
$.each(content, (id, value) -> | |
$("#content").prepend(<%= j render 'content', content: Content.find(id)%>) | |
) | |
else | |
console.log("Nothing") | |
), 5000 |
This file contains hidden or 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 EndpointsController < ApplicationController | |
def index | |
# Empty action/splash page with link to create a new endpoint | |
@endpoint = Endpoint.new | |
end | |
def create | |
@endpoint = Endpoint.create(token: Endpoint.generate_token) | |
redirect_to endpoint_token_path @endpoint.token | |
end | |
def show | |
show_endpoint Endpoint.find(params[:id]) | |
end | |
def show_with_token | |
show_endpoint Endpoint.find_by_token params[:token] | |
end | |
def new_content | |
@endpoint = Endpoint.find(params[:endpoint_id]) | |
last_content = @endpoint.content.last | |
if last_content.id <= params[:last_content_id].to_i | |
new_content = {content: nil} | |
else | |
content = @endpoint.content.where("id > #{params[:last_content_id]}") | |
#new_content looks like | |
# { content: | |
# { | |
# 5: "{key: value}", | |
# 7: "{another_key: another_value}" | |
# } | |
# } | |
new_content = {content: content.collect { |v| [v.id] }} | |
end | |
render json: new_content.to_json | |
end | |
protected | |
# DRYing up the code a little | |
def show_endpoint endpoint | |
@endpoint = endpoint | |
@content = @endpoint.content.order("id DESC") | |
render :show | |
end | |
end |
This file contains hidden or 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
.container | |
.row.demo-row | |
.span12{:style => "margin-top: 10px; margin-left:"} | |
.navbar.navbar-inverse | |
.navbar-inner | |
.container | |
%button.btn.btn-navbar{"data-target" => "#nav-collapse-01", "data-toggle" => "collapse", :type => "button"} | |
#nav-collapse-01.nav-collapse.collapse | |
%ul.nav | |
%li | |
=link_to "OYSTER", root_path | |
%li{:style => ""} | |
%input.span8{:style => "\n height: 17px;\n border: 1px solid #000000;\n margin-bottom: 0;\n margin-top: 9px;\n", :type => "text", :value => "#{request.protocol}#{request.host_with_port}#{request.fullpath}"} | |
/ /.nav | |
.container | |
.row.demo-samples | |
#content.span9{:style => "-moz-border-radius: 8px 8px 6px 6px; border-radius: 8px 8px 6px 6px;", data: {update_path: new_content_path(@endpoint.id, 0) }} | |
[email protected] do |content| | |
=render 'content', content: content | |
.span3 | |
.todo.mrm | |
.todo-search | |
%input.todo-search-field{:placeholder => "Search", :type => "search", :value => ""} | |
%ul | |
%li.todo-done | |
.todo-content | |
%h4.todo-name | |
Load new POST requests | |
/ /todo list | |
=render 'footer' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment