Skip to content

Instantly share code, notes, and snippets.

Avatar

Paul Smith paulcsmith

View GitHub Profile
View admin.cr
class Admin < BaseModel
table do
column name : String
belongs_to user : User
end
end
View lucky_serializer_example.cr
# src/actions/rss/show.cr
#...
xml ArticlesXmlSerializer.new(articles, title: "Feed Name", description: "Here's the descr", path: request.path).render
#...
# src/actions/xml_action.cr
abstract class XMLAction < Lucky::Action
private def xml(body : String)
Lucky::TextResponse.new(context, content_type: "text/xml; charset=utf-8", body: body, status: 200)
end
@paulcsmith
paulcsmith / comment_view.ex
Last active Aug 29, 2015 — forked from jeregrine/comment_view.ex
Rendering JSON with views
View comment_view.ex
defmodule MyApp.CommentView do
use MyApp.Web, :view
@attributes ~W(id name inserted_at)
def render("index.json", %{data: comments}) do
for comment <- comments, do: render("show.json", %{data: comment})
end
def render("show.json", %{data: comment}) do
comment
View citizenship_status.rb
module Colleague::Classes
class CitizenshipStatus
include Processor
def process_field(value)
AlienStatus.find_code( value )
end
end
end