<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Serabe Reloaded &#187; Ruby on Rails</title>
	<atom:link href="http://www.serabe.com/category/programacion/ruby/ruby-on-rails/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.serabe.com</link>
	<description>Conecto ergo sum. Non conecto ergo urgueo.</description>
	<lastBuildDate>Sun, 09 Oct 2011 21:30:53 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Adding organization repos to Travis-CI: Part I</title>
		<link>http://www.serabe.com/2011/10/09/adding-organization-repos-to-travis-ci-part-i/</link>
		<comments>http://www.serabe.com/2011/10/09/adding-organization-repos-to-travis-ci-part-i/#comments</comments>
		<pubDate>Sun, 09 Oct 2011 21:30:53 +0000</pubDate>
		<dc:creator>Serabe</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[Ruby on Rails]]></category>
		<category><![CDATA[opensource]]></category>
		<category><![CDATA[sproutcore]]></category>
		<category><![CDATA[travis-ci]]></category>

		<guid isPermaLink="false">http://www.serabe.com/?p=594</guid>
		<description><![CDATA[It was a nice Friday, Porras and I were at the BeBanjOffice and  we were working on adding organization support to Travis-CI. First, we needed to find where the user repos were being fetch. Said and done, we found that travis is using the ServiceHookController to ask the server for repos (and to update them too, but [...]]]></description>
			<content:encoded><![CDATA[<p>It was a <a href="https://bebanjo.jottit.com/open_source_fridays" title="Open Source Fridays" >nice Friday</a>, <a href="https://github.com/porras" title="Porras' Github Profile" >Porras</a> and I were at the BeBanjOffice and  we were working on adding organization support to <a href="http://travis-ci.org/" title="Travis CI" >Travis-CI</a>.</p>
<p>First, we needed to find where the user repos were being fetch. Said and done, we found that travis is using the <a href="https://github.com/porras/travis-ci/blob/66c763df9f1bf298aa8871816f7bcaf1bfbff30b/app/controllers/service_hooks_controller.rb" title="ServiceHookController in Github" >ServiceHookController</a> to ask the server for repos (and to update them too, but don&#8217;t hurry, we&#8217;ll get there in part II). The controller was using the <a href="https://github.com/porras/travis-ci/blob/66c763df9f1bf298aa8871816f7bcaf1bfbff30b/app/models/user.rb#L40" title="github_repositories" >github_repositories</a> method in the <a href="https://github.com/porras/travis-ci/blob/66c763df9f1bf298aa8871816f7bcaf1bfbff30b/app/models/user.rb" title="User model" >User model</a>. Finally, we arrived to <a href="https://github.com/porras/travis-ci/blob/66c763df9f1bf298aa8871816f7bcaf1bfbff30b/lib/travis/github_api.rb" title="Travis::GithubApi" >Travis::GithubApi</a>, where all our questions found answers.</p>
<p><a href="https://github.com/porras/travis-ci/blob/66c763df9f1bf298aa8871816f7bcaf1bfbff30b/lib/travis/github_api.rb#L32" title="repositories_for_user method" >repositories_for_user</a> just relied on <code>Octokit#repositories</code> for getting the repos, so we added all the code after the plus sign. You might think that this code lacks the proper security, is wrong and that it shouldn&#8217;t be there (and damn it, you&#8217;re right!) but there is no easy way to retrieve only the repos where the user has admin privileges (we wasted hours on this and a quick message to Github confirmed it).  Basically, it asks for all organizations for the given user (beware! You need to make your membership public, otherwise it won&#8217;t work) and then flat_map them to the repos in the given organization (whether the user can administrate them or not).</p>
<p>Later, the <code>each</code> block was added so we could know whether the repo belongs to the user or to an organization.</p>
<h2>Stop! Hammertime!</h2>
<p>We needed a way to let the user know that a repo actually belongs to an organization, so we added that info to the <a href="https://github.com/porras/travis-ci/blob/66c763df9f1bf298aa8871816f7bcaf1bfbff30b/app/assets/javascripts/app/templates/service_hooks/list.jst.hjs" title="Template code." >template</a> (that <code>{{#if content.organization_name}}</code> is ours <img src='http://www.serabe.com/wp-includes/images/smilies/icon_biggrin.gif' alt="icon biggrin Adding organization repos to Travis CI: Part I" class='wp-smiley' title="Adding organization repos to Travis CI: Part I" /> ) and added some <a href="https://github.com/porras/travis-ci/blob/66c763df9f1bf298aa8871816f7bcaf1bfbff30b/app/assets/stylesheets/application.scss#L909" title="SCSS code" >style</a> so it could look this awesome:</p>
<div class="thumbnail"><a href="http://skitch.com/e-serabe/fhqxc/travis-ci-distributed-build-platform-for-the-open-source-community" ><img style="max-width: 638px;" src="http://img.skitch.com/20110928-q5hyhyuddmqnsr7awgmxtj6ph5.medium.jpg" alt="20110928 q5hyhyuddmqnsr7awgmxtj6ph5.medium Adding organization repos to Travis CI: Part I"  title="Adding organization repos to Travis CI: Part I" /></a></div>
<p>We had some tough time trying to get it vertically centered, but after realizing that Github has its tags the same way as we do, we stop trying to fix it. And they still look awesome.</p>
<p>More coming in part II.</p>
<div class="evernoteSiteMemory"><a href="javascript:" onclick="Evernote.doClip({title: 'Adding organization repos to Travis-CI: Part I on Serabe Reloaded',url: 'http://www.serabe.com/2011/10/09/adding-organization-repos-to-travis-ci-part-i/',contentID: 'post-594',suggestTags: 'opensource,Ruby,sproutcore,travis-ci',providerName: 'Serabe Reloaded',styling: 'text' });return false" class="evernoteSiteMemoryLink"><img src="http://static.evernote.com/article-clipper.png" class="evernoteSiteMemoryButton" title="Adding organization repos to Travis CI: Part I" alt="article clipper Adding organization repos to Travis CI: Part I" />
				</a>				<div class="evernoteSiteMemoryClear">&nbsp;</div>
</div><p><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fwww.serabe.com%2F2011%2F10%2F09%2Fadding-organization-repos-to-travis-ci-part-i%2F&amp;title=Adding%20organization%20repos%20to%20Travis-CI%3A%20Part%20I" id="wpa2a_2"><img src="http://www.serabe.com/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="share save 171 16 Adding organization repos to Travis CI: Part I"  title="Adding organization repos to Travis CI: Part I" /></a></p>]]></content:encoded>
			<wfw:commentRss>http://www.serabe.com/2011/10/09/adding-organization-repos-to-travis-ci-part-i/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Anidamiento de recursos con REST en Ruby on Rails Ã³ cÃ³mo acceder de dos maneras distintas a un mismo controlador utilizando REST con Ruby On Rails.</title>
		<link>http://www.serabe.com/2007/09/03/anidamiento-de-recursos-con-rest-en-ruby-on-rails-o-como-acceder-de-dos-maneras-distintas-a-un-mismo-controlador-utilizando-rest-con-ruby-on-rails/</link>
		<comments>http://www.serabe.com/2007/09/03/anidamiento-de-recursos-con-rest-en-ruby-on-rails-o-como-acceder-de-dos-maneras-distintas-a-un-mismo-controlador-utilizando-rest-con-ruby-on-rails/#comments</comments>
		<pubDate>Mon, 03 Sep 2007 21:37:34 +0000</pubDate>
		<dc:creator>Serabe</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[REST]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[Ruby on Rails]]></category>

		<guid isPermaLink="false">http://www.serabe.com/2007/09/03/anidamiento-de-recursos-con-rest-en-ruby-on-rails-o-como-acceder-de-dos-maneras-distintas-a-un-mismo-controlador-utilizando-rest-con-ruby-on-rails/</guid>
		<description><![CDATA[DespuÃ©s de un tÃ­tulo tan largo, lo primero es meter en situaciÃ³n. Tengo una web que tiene temas, en cada tema hay mÃ¡s temas y descargas. Estos se muestran con los controladores topics y downloads respectivamente. El problema venÃ­a puesto que los controladores se tenÃ­an que poder acceder de dos formas. En el caso de [...]]]></description>
			<content:encoded><![CDATA[<p>DespuÃ©s de un tÃ­tulo tan largo, lo primero es meter en situaciÃ³n. Tengo una web que tiene temas, en cada tema hay mÃ¡s temas y descargas. Estos se muestran con los controladores <em>topics</em> y <em>downloads</em> respectivamente. El problema venÃ­a puesto que los controladores se tenÃ­an que poder acceder de dos formas. En el caso de las descargas:</p>
<p><strong>1.-</strong> /<em>downloads</em><br />
<strong>2.-</strong> /<em>topics</em>/<strong>:topic_id</strong>/<em>downloads</em></p>
<p>En el caso de los temas:<br />
<em><br />
</em><strong>1.-</strong> /<em>topics</em><br />
<strong>2.-</strong> /<em>topics</em>/<strong>:topic_id</strong>/<em>topics</em></p>
<p><strong>AproximaciÃ³n: Crear un segundo controlador.</strong></p>
<p>Empecemos por el tema de los temas y sus subtemas. En este caso utilizaremos un segundo controlador al que llamaremos <em>subtopic</em>. Para poder acceder de la forma buscada hay que sustituir en el archivo <em>config</em>/<em>routes.rb </em>la lÃ­nea</p>
<p><code>map.resources :topics</code><br />
por lo siguiente:</p>
<p><code>map.resources :topics do |topic|<br />
topic.resources :subtopics, :path_prefix =&gt; "topics/:topic_id"<br />
end</code><br />
DespuÃ©s, se eliminan los mÃ©todos <em>delete</em>, <em>edit</em>, <em>show</em> y <em>update</em>, pues sÃ³lo se necesitan los mÃ©todos <em>create</em>, <em>index</em> y <em>new</em>. AdemÃ¡s, lo mÃ¡s lÃ³gico serÃ­a implementar los mÃ©todos <em>create</em>, <em>index</em> y <em>new</em> de forma que podamos aprovechar las vistas del controlador <em>topic</em>. AÃºn asÃ­, tenemos repeticiÃ³n, lo que viola el principio DRY que rige a Rails. Por lo tanto, veamos cÃ³mo podemos conseguir el resultado obtenido de una forma mÃ¡s sencilla y elegante.</p>
<p><strong>Fase final: las cosas bien hechas.</strong></p>
<p>En este caso cogeremos como ejemplo las descargas de un tema. Para ello, al igual que en el ejemplo anterior, hay que modificar el <em>routes.rb</em> aÃ±adiÃ©ndole las siguientes lÃ­neas</p>
<p><code>map.resources :topics do |topic|<br />
topic.resources :downloads, :path_prefix =&gt; "topics/:topic_id", :name_prefix =&gt; 'topic_'<br />
end</p>
<p>map.resources :downloads</code></p>
<p>Hay que recalcar dos aspectos de estas rutas. En primer lugar, el :name_prefix. De esta forma, podremos diferenciar entre si hay que crear un path del tipo /<em>downloads</em>/<em>1</em> o del tipo /<em>topics</em>/<strong>:topic_id</strong>/<em>downloads</em> simplemente precediendo el nombre de los mÃ©todos que construyen el path con <em>topic_</em>. Es decir, si utilizamos el mÃ©todo <code>edit_download_path(download)</code> obtenemos la ruta <em>http://localhost:3000/downloads/2;edit</em>. En cambio, al utilizar el mÃ©todo <code>topic_edit_download_path(download.topic,download)</code> (hay que recalcar que el <em>:name_prefix</em> va antes del nombre normal del mÃ©todo y que los parÃ¡metros se pasan segÃºn el orden en el que se encuentran en la ruta) obtenemos la ruta <em>http://localhost:3000/topics/1/downloads/2;edit</em>.<br />
Espero que este artÃ­culo os haya sido tan interesante (aunque me exprese como el culo) como para mÃ­ fue el investigar cÃ³mo se hace esta monerÃ­a con REST, Ruby y Ruby on Rails.</p>
<div class="evernoteSiteMemory"><a href="javascript:" onclick="Evernote.doClip({title: 'Anidamiento de recursos con REST en Ruby on Rails Ã³ cÃ³mo acceder de dos maneras distintas a un mismo controlador utilizando REST con Ruby On Rails. on Serabe Reloaded',url: 'http://www.serabe.com/2007/09/03/anidamiento-de-recursos-con-rest-en-ruby-on-rails-o-como-acceder-de-dos-maneras-distintas-a-un-mismo-controlador-utilizando-rest-con-ruby-on-rails/',contentID: 'post-114',suggestTags: '',providerName: 'Serabe Reloaded',styling: 'text' });return false" class="evernoteSiteMemoryLink"><img src="http://static.evernote.com/article-clipper.png" class="evernoteSiteMemoryButton" title="Anidamiento de recursos con REST en Ruby on Rails Ã³ cÃ³mo acceder de dos maneras distintas a un mismo controlador utilizando REST con Ruby On Rails." alt="article clipper Anidamiento de recursos con REST en Ruby on Rails Ã³ cÃ³mo acceder de dos maneras distintas a un mismo controlador utilizando REST con Ruby On Rails." />
				</a>				<div class="evernoteSiteMemoryClear">&nbsp;</div>
</div><p><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fwww.serabe.com%2F2007%2F09%2F03%2Fanidamiento-de-recursos-con-rest-en-ruby-on-rails-o-como-acceder-de-dos-maneras-distintas-a-un-mismo-controlador-utilizando-rest-con-ruby-on-rails%2F&amp;title=Anidamiento%20de%20recursos%20con%20REST%20en%20Ruby%20on%20Rails%20%C3%83%C2%B3%20c%C3%83%C2%B3mo%20acceder%20de%20dos%20maneras%20distintas%20a%20un%20mismo%20controlador%20utilizando%20REST%20con%20Ruby%20On%20Rails." id="wpa2a_4"><img src="http://www.serabe.com/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="share save 171 16 Anidamiento de recursos con REST en Ruby on Rails Ã³ cÃ³mo acceder de dos maneras distintas a un mismo controlador utilizando REST con Ruby On Rails."  title="Anidamiento de recursos con REST en Ruby on Rails Ã³ cÃ³mo acceder de dos maneras distintas a un mismo controlador utilizando REST con Ruby On Rails." /></a></p>]]></content:encoded>
			<wfw:commentRss>http://www.serabe.com/2007/09/03/anidamiento-de-recursos-con-rest-en-ruby-on-rails-o-como-acceder-de-dos-maneras-distintas-a-un-mismo-controlador-utilizando-rest-con-ruby-on-rails/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

