Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
tree: a802d9f140
Fetching contributors…

Cannot retrieve contributors at this time

65 lines (54 sloc) 4.577 kB
{% extends "guide.html" %}
{% block guide_content %}
<p>Here's the code you'd write with Boss to define, create, save, and display relational records in the obligatory blog application:</p>
<p>model/blog_post.erl:</p>
<div class="code">
<span class="attr">-module</span>(blog_post, [Id, Title, Text, AuthorId]).<br />
<span class="attr">-compile</span>(export_all).<br />
<span class="attr">-belongs_to</span>(author).
</div>
<p>model/author.erl:</p>
<div class="code">
<span class="attr">-module</span>(author, [Id, Name]).<br />
<span class="attr">-compile</span>(export_all).<br />
<span class="attr">-has</span>({blog_posts, many}).
</div>
<p>controller/blog_post_controller.erl:</p>
<div class="code">
<span class="attr">-module</span>(blog_post_controller, [Instance, Req]).<br />
<span class="attr">-compile</span>(export_all).<br />
<br />
create(<span class="atom">'GET'</span>, []) -&gt;<br />
&nbsp;&nbsp;&nbsp;&nbsp;ok;<br />
create(<span class="atom">'POST'</span>, []) -&gt;<br />
&nbsp;&nbsp;&nbsp;&nbsp;FakeAuthor = (<span class="function">author</span>:<span class="function">new</span>(id, <span class="string">"Mark Twain"</span>)):<span class="function">save</span>(),<br />
&nbsp;&nbsp;&nbsp;&nbsp;BlogPost = <span class="function">blog_post</span>:<span class="function">new</span>(id,<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="function">Req</span>:<span class="function">post_value</span>(<span class="string">"title"</span>), <br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="function">Req</span>:<span class="function">post_value</span>(<span class="string">"text"</span>), <br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="function">FakeAuthor</span>:<span class="function">id</span>()),<br />
&nbsp;&nbsp;&nbsp;&nbsp;{ok, SavedBlogPost} = <span class="function">BlogPost</span>:<span class="function">save</span>(),<br />
&nbsp;&nbsp;&nbsp;&nbsp;{redirect, <span class="string">"/blog_post/view/"</span>++<span class="function">SavedBlogPost</span>:<span class="function">id</span>()}.<br />
<br />
view(<span class="atom">'GET'</span>, [BlogPostId]) -&gt;<br />
&nbsp;&nbsp;&nbsp;&nbsp;{ok, [{blog_post, <span class="function">boss_db</span>:<span class="function">find</span>(BlogPostId)}]}.<br />
</div>
<p>view/blog_post/create.html:</p>
<div class="code">
<span class="bracket">&lt;<span class="name">form</span> <span class="attr">method</span>=<span class="string">&quot;post&quot;</span>&gt;</span><br />
Title: <span class="bracket">&lt;<span class="name">input</span> <span class="attr">name</span>=<span class="string">&quot;title&quot;</span>&gt;</span><span class="bracket">&lt;<span class="name">br</span> /&gt;</span><br />
Text: <span class="bracket">&lt;<span class="name">textarea</span> <span class="attr">name</span>=<span class="string">&quot;text&quot;</span>&gt;</span><span class="bracket">&lt;/<span class="name">textarea</span>&gt;</span><span class="bracket">&lt;<span class="name">br</span> /&gt;</span><br />
<span class="bracket">&lt;<span class="name">input</span> <span class="attr">type</span>=<span class="string">&quot;submit&quot;</span>&gt;</span><br />
<span class="bracket">&lt;/<span class="name">form</span>&gt;</span>
</div>
<p>view/blog_post/view.html:</p>
<div class="code">
<span class="bracket">&lt;<span class="name">h1</span>&gt;</span><span class="braces">{{ "{{" }}</span> <span class="var">blog_post</span>.<span class="attr">title</span> <span class="braces">{{ "}}" }}</span><span class="bracket">&lt;/<span class="name">h1</span>&gt;</span><br />
By <span class="braces">{{ "{{" }}</span> <span class="var">blog_post</span>.<span class="attr">author</span>.<span class="attr">name</span> <span class="braces">{{ "}}" }}</span><br />
(Post #<span class="braces">{{ "{{" }}</span> <span class="var">blog_post</span>.<span class="attr">author</span>.<span class="attr">blog_posts</span>|length <span class="braces">{{ "}}" }}</span>)<br />
<span class="bracket">&lt;<span class="name">p</span>&gt;</span><span class="braces">{{ "{{" }}</span> <span class="var">blog_post</span>.<span class="attr">text</span> <span class="braces">{{ "}}" }}</span><span class="bracket">&lt;/<span class="name">p</span>&gt;</span>
</div>
<p>Database schema:</p>
<div class="code" style="text-align: center;">NONE</div>
<p>URL configuration file:</p>
<div class="code" style="text-align: center;">NONE</div>
{% endblock %}
Jump to Line
Something went wrong with that request. Please try again.