Refactor
:my
=>
'code'
Codes
Refactorings
Popular
Best
Submit
Spam
Account
Logout
Login
JavaScript doesn't seem to be activated, expect things to be ugly and sloppy!
Learn How to Create Your Own Programming Language
createyourproglang.com
Recent
Ultra lightweight message "popup" at top of parent element
Good way to output menu with submenu through a module?!
Moving Code from Controller to Model
Get Site Information with PHP
Help with module?!
Node.js: Calculating total filesize of 3 files
convert single itemed sub-arrays into string
Access HashMap key by value
Language Selection
Generating a list of 3 entries with the rest hidden
Popular
Good way to output menu with submenu through a module?!
Ultra lightweight message "popup" at top of parent element
Moving Code from Controller to Model
Double 'if'
Language Selection
Help with module?!
Fetch and parse feeds with feedzirra
Generating a list of 3 entries with the rest hidden
Access HashMap key by value
Node.js: Calculating total filesize of 3 files
Pastable version of
resource_controller: Redesign My API
<div style="overflow:auto;border:solid 1px #ccc;background:#000;color:#F8F8F8"> <div class="section"> <span style="margin:0;padding:4px 6px;font-size:12px;float:right;">Before / After / Response</span> <pre style="float:left;margin:0 10px;border-right:0;color:#666;">1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23</pre> <pre class="sunburst"> <span style="color:#E28964;">class</span> <span style="text-decoration:underline;">PostsController<span style="color:#9B5C2E;font-style:italic;"> <span style="color:#9B5C2E;font-style:italic;"><</span> ResourceController::Base</span></span> <span style="color:#AEAEAE;font-style:italic;"> <span style="color:#AEAEAE;font-style:italic;">#</span> block syntax</span> create <span style="color:#E28964;">do</span> before { <span style="color:#3E87E3;"><span style="color:#3E87E3;">@</span>post</span>.<span style="color:#89BDFF;">user</span> <span style="color:#E28964;">=</span> current_user } response <span style="color:#E28964;">do </span>|<span style="color:#3E87E3;">wants</span>| wants.<span style="color:#89BDFF;">html</span> wants.<span style="color:#89BDFF;">js</span> <span style="color:#E28964;">end</span> <span style="color:#E28964;">end</span> <span style="color:#AEAEAE;font-style:italic;"> <span style="color:#AEAEAE;font-style:italic;">#</span> chain syntax</span> update.<span style="color:#89BDFF;">failure</span>.<span style="color:#89BDFF;">wants</span>.<span style="color:#89BDFF;">js</span> <span style="color:#AEAEAE;font-style:italic;"> <span style="color:#AEAEAE;font-style:italic;">#</span> hybrid syntax</span> update.<span style="color:#89BDFF;">failure</span> <span style="color:#E28964;">do</span> flash <span style="color:#65B042;"><span style="color:#65B042;">"</span>There was a problem saving your object.<span style="color:#65B042;">"</span></span> wants.<span style="color:#89BDFF;">js</span> <span style="color:#E28964;">end</span> <span style="color:#E28964;">end</span> </pre> </div> </div> <div style="overflow:auto;border:solid 1px #ccc;background:#000;color:#F8F8F8"> <div class="section"> <span style="margin:0;padding:4px 6px;font-size:12px;float:right;">Alternate Model/Route/Object Naming</span> <pre style="float:left;margin:0 10px;border-right:0;color:#666;">1 2 3 4 5 6 7 8 9 10 11 12</pre> <pre class="sunburst"> <span style="color:#E28964;">class</span> <span style="text-decoration:underline;">PostsController<span style="color:#9B5C2E;font-style:italic;"> <span style="color:#9B5C2E;font-style:italic;"><</span> ResourceController::Base</span></span> <span style="color:#E28964;">private</span> <span style="color:#E28964;">def</span> <span style="color:#89BDFF;">model_name</span> <span style="color:#65B042;"><span style="color:#65B042;">'</span>blog_post<span style="color:#65B042;">'</span></span> <span style="color:#E28964;">end</span> <span style="color:#E28964;">def</span> <span style="color:#89BDFF;">route_name</span> <span style="color:#65B042;"><span style="color:#65B042;">'</span>article<span style="color:#65B042;">'</span></span> <span style="color:#E28964;">end</span> <span style="color:#E28964;">end</span> </pre> </div> </div> <div style="overflow:auto;border:solid 1px #ccc;background:#000;color:#F8F8F8"> <div class="section"> <span style="margin:0;padding:4px 6px;font-size:12px;float:right;">Alternate find syntax</span> <pre style="float:left;margin:0 10px;border-right:0;color:#666;">1 2 3 4 5 6 7 8 9 10 11 12</pre> <pre class="sunburst"> <span style="color:#E28964;">class</span> <span style="text-decoration:underline;">PostsController<span style="color:#9B5C2E;font-style:italic;"> <span style="color:#9B5C2E;font-style:italic;"><</span> ResourceController::Base</span></span> <span style="color:#E28964;">private</span> <span style="color:#E28964;">def</span> <span style="color:#89BDFF;">object</span> <span style="color:#3E87E3;"><span style="color:#3E87E3;">@</span>object</span> <span style="color:#E28964;">||=</span> end_of_association_chain.<span style="color:#89BDFF;">find_by_permalink</span>(param) <span style="color:#E28964;">end</span> <span style="color:#E28964;">def</span> <span style="color:#89BDFF;">collection</span> <span style="color:#3E87E3;"><span style="color:#3E87E3;">@</span>collection</span> <span style="color:#E28964;">||=</span> end_of_association_chain.<span style="color:#89BDFF;">find</span>(<span style="color:#3387CC;"><span style="color:#3387CC;">:</span>all</span>, <span style="color:#3387CC;"><span style="color:#3387CC;">:</span>page</span> => {<span style="color:#3387CC;"><span style="color:#3387CC;">:</span>current</span> => params[<span style="color:#3387CC;"><span style="color:#3387CC;">:</span>page</span>], <span style="color:#3387CC;"><span style="color:#3387CC;">:</span>size</span> => <span style="color:#3387CC;">10</span>}) <span style="color:#E28964;">end</span> <span style="color:#E28964;">end</span> </pre> </div> </div> <div style="overflow:auto;border:solid 1px #ccc;background:#000;color:#F8F8F8"> <div class="section"> <span style="margin:0;padding:4px 6px;font-size:12px;float:right;">Specific Actions</span> <pre style="float:left;margin:0 10px;border-right:0;color:#666;">1 2 3 4 5</pre> <pre class="sunburst"> <span style="color:#E28964;">class</span> <span style="text-decoration:underline;">PostsController<span style="color:#9B5C2E;font-style:italic;"> <span style="color:#9B5C2E;font-style:italic;"><</span> ResourceController::Base</span></span> actions <span style="color:#3387CC;"><span style="color:#3387CC;">:</span>all</span>, <span style="color:#3387CC;"><span style="color:#3387CC;">:</span>except</span> => <span style="color:#3387CC;"><span style="color:#3387CC;">:</span>edit</span> <span style="color:#E28964;">end</span> </pre> </div> </div> <div style="overflow:auto;border:solid 1px #ccc;background:#000;color:#F8F8F8"> <div class="section"> <span style="margin:0;padding:4px 6px;font-size:12px;float:right;">Possible Parents</span> <pre style="float:left;margin:0 10px;border-right:0;color:#666;">1 2 3 4</pre> <pre class="sunburst"> <span style="color:#E28964;">class</span> <span style="text-decoration:underline;">PostsController<span style="color:#9B5C2E;font-style:italic;"> <span style="color:#9B5C2E;font-style:italic;"><</span> ResourceController::Base</span></span> belongs_to <span style="color:#3387CC;"><span style="color:#3387CC;">:</span>user</span>, <span style="color:#3387CC;"><span style="color:#3387CC;">:</span>category</span> <span style="color:#E28964;">end</span> </pre> </div> </div> <a href="http://refactormycode.com/codes/137-resource_controller-redesign-my-api" style="color:#fff" title="As seen on RefactorMyCode.com"><img alt="Small_logo" src="http://refactormycode.com/images/small_logo.gif" style="border:0" /></a>