So the above is a partial (but you already knew that by convention), that has examples of binding (model changes forces view update) and the Named Routing syntax of Batman. Makes sense.
%a.btn.btn-primary{"data-route"=>'routes.posts.new'} New Post
.row#content.span12#posts%div{"data-foreach-post"=>"posts"}.post{"data-partial"=>"posts/_post"}
Check out how you iterate over “enumerables” and include partials.
%fieldset%legend%span{"data-hideif"=>"post.id"} New Post
%span{"data-showif"=>"post.id"} Edit Post
#error-explanation.alert-message.block-message.error{"data-showif"=>"post.errors.length"}%p%strong%span{"data-bind"=>"post.errors.length"}%span{"data-bind"=>"'error' | pluralize post.errors.length"} prevented this post from being created:
%ul%li{"data-bind"=>"error.message","data-foreach-error"=>"post.errors"}.clearfix{"data-addclass-error"=>'post.errors.title.length'}%label{:for=>"post_title"} Title
.input%input#post_title.span8{"data-bind"=>"post.title",:name=>"post[title]",:size=>"30",:type=>"text"}%fieldset.clearfix{"data-addclass-error"=>'post.errors.content.length'}%label{:for=>"post_content"} Description
.input%textarea#post_content.span8{:cols=>"40","data-bind"=>"post.content",:name=>"post[content]",:rows=>"20"}.actions%input.btn.btn-primary{:name=>"commit",:type=>"submit",:value=>"Submit"}%a.btn{'data-route'=>'Post'} Cancel
Finally, the form partial has some logic to make the validation errors show up and so on. We also see some of the conditionals, pretty neat.
Pause for a second. The basic CRUD app is done. Fastest time to this stage of any framework I’ve looked at (I was timing productivity both in learning the frameworks from scratch and production of form crud). While figuring out how to do this took a much longer time, if you are following along I bet you got to this point under 30 minutes.
That’s pretty quick!
Next time, associations.
PS - And if you want it to look pretty, here’s the SASS I’m using:
// Place all the styles related to the posts controller here.// They will automatically be included in application.css.// You can use Sass (SCSS) here: sass-lang.com/// Set the correct sprite paths$iconSpritePath:image-path('glyphicons-halflings.png');$iconWhiteSpritePath:image-path('glyphicons-halflings-white.png');//$navbarBackground: #555;//$navbarBackgroundHighlight: #888;//$navbarText: #eee;//$navbarLinkColor: #eee;@import"bootstrap";body{padding-top:40px;}@import"bootstrap-responsive";.navbar.brand{//color: #FAFFB8;}// Place all the styles related to the memories controller here.// They will automatically be included in application.css.// You can use Sass (SCSS) here: sass-lang.com/h1,h2,h3,h4,h5,h6,p,div{font-family:museo-slab,sans-serif;}html,body{background-color:#eee;}.container>footerp{text-align:center;/* center align it with the container */}/* The white background content wrapper */.content{background-color:#fff;padding:20px;margin:0-20px;/* negative indent the amount of the padding to maintain the grid system */-webkit-border-radius:006px6px;-moz-border-radius:006px6px;border-radius:006px6px;-webkit-box-shadow:01px2pxrgba(0,0,0,.15);-moz-box-shadow:01px2pxrgba(0,0,0,.15);box-shadow:01px2pxrgba(0,0,0,.15);}.notice{border:#4444471pxsolid;padding:10px;margin:10px0;}#error-explanationul{margin:10px15px;}.error{border:1pxsolid#c87872;padding:10px;margin:10px0;}#posts{list-style-type:none;}