<?xml version="1.0" encoding="UTF-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
  <id>http://blog.codingspree.net/</id>
  <title>mgutz.com Syndication</title>
  <updated>2011-10-11T21:00:00Z</updated>
  <link rel="alternate" href="http://blog.codingspree.net/"/>
  <link rel="self" href="http://blog.codingspree.net/atom.xml"/>
  <author>
    <name>Mario Gutierrez</name>
    <uri>http://mgutz.com</uri>
  </author>
  <entry>
    <id>tag:blog.codingspree.net,2011-10-12:/2011/10/12/basic_authentication_and_rewire_rules_for_you_engine_yard_application.html</id>
    <title type="html">Adding Basic Authentication And Rewirite Rules to Your Engine Yard Application</title>
    <published>2011-10-11T21:00:00Z</published>
    <updated>2011-10-12T16:13:19Z</updated>
    <link rel="alternate" href="http://blog.codingspree.net/2011/10/12/basic_authentication_and_rewire_rules_for_you_engine_yard_application.html"/>
    <content type="html">&lt;p&gt;Today I've decided to clean up and put some order in our Nginx setup and customizations for app hosted on AppCloud.&lt;/p&gt;

&lt;p&gt;Till now we're using &lt;a href="http://docs.engineyard.com/configuration-keep-files.html"&gt;keep files&lt;/a&gt; to add basic authentication for our staging and #{application}.rewites file for the rewrite rules. Turns out few things changed since last time I looked at these.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Tip&lt;/strong&gt; (straight from the docs): Where possible, consider using an include file instead of a keep file.&lt;/p&gt;

&lt;p&gt;So I've decided to move basic authenticatin stuff to &lt;code&gt;/etc/nginx/servers/#{application}/custom.locations.conf&lt;/code&gt; as described &lt;a href="http://quickleft.com/blog/93"&gt;here&lt;/a&gt;, but soon I found out that it's not working that way anymore. As it's stated in &lt;a href="http://docs.engineyard.com/appcloud_update_2011_05_18.html"&gt;that AppCloud update notes&lt;/a&gt;&lt;/p&gt;

&lt;pre&gt;
Deprecated usage:
  /etc/nginx/servers/#{application}.rewrites
  /etc/nginx/servers/#{application}/custom.locations.conf
both are replaced by:
  /etc/nginx/servers/#{application}/custom.conf
&lt;/pre&gt;


&lt;p&gt;Here are the steps how to add basic authentication to your app:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;ssh to your app&lt;/li&gt;
&lt;li&gt;&lt;code&gt;cd /data/nginx/servers&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;Open the custom.conf file by typing: &lt;code&gt;vim #{application}/custom.conf&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;Add in the following code (don;t forget to change #{application} with your EY app name
&lt;pre&gt;
auth_basic  "Restricted";
auth_basic_user_file  /data/nginx/servers/#{application}/#{application}.users;
passenger_enabled on;
&lt;/pre&gt;
Hit :wq to save and quit vim.&lt;/li&gt;
&lt;li&gt;Create #{application}.users file by typing
&lt;code&gt;htpasswd -c /data/nginx/servers/#{application}/#{application}.users #{user_name}&lt;/code&gt;.
Don't forget to replace #{application} and #{user_name}/&lt;/li&gt;
&lt;li&gt;Restart nginx using &lt;code&gt;sudo /etc/init.d/nginx restart&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;Revisit your app and you should have the basic authentication pop-up on your site.&lt;/li&gt;
&lt;/ul&gt;


&lt;p&gt;Same for your rewrite rules. Since &lt;code&gt;/etc/nginx/servers/#{application}.rewrites&lt;/code&gt; is deprecated, just put your rules in &lt;code&gt;/etc/nginx/servers/#{application}/custom.conf&lt;/code&gt;. At the end it should look, for example, something like&lt;/p&gt;

&lt;pre&gt;
  auth_basic  "Restricted";
  auth_basic_user_file  /data/nginx/servers/#{application}/#{application}.users;
  passenger_enabled on;

  rewrite ^/members/(.*)/blog_entries/(.*)$  /members/$1/blog/$2 permanent;
&lt;/pre&gt;


&lt;p&gt;Hope this helps. I'll try to keep it updated if anything changes, but if you see a problem, just drop a comment.&lt;/p&gt;
</content>
    <summary type="html">How to add HTTP basic authentication and custom rewirite rules to application hosted on Engine Yard's AppCloud.</summary>
  </entry>
  <entry>
    <id>tag:blog.codingspree.net,2011-06-18:/2011/06/18/scoping_resources_in_activeadmin.html</id>
    <title type="html">Scoping resources in ActiveAdmin</title>
    <published>2011-06-17T21:00:00Z</published>
    <updated>2011-06-18T15:57:40Z</updated>
    <link rel="alternate" href="http://blog.codingspree.net/2011/06/18/scoping_resources_in_activeadmin.html"/>
    <content type="html">&lt;p&gt;Here's the use case I had yesterday.&lt;/p&gt;

&lt;p&gt;We're using &lt;a href="http://activeadmin.info/"&gt;ActiveAdmin&lt;/a&gt; in our current Rails 3 project. It's really cool and gives you an easy way to jump start your admin section.
Of course the more you want to customize, the more code you have to write. In our case we wanted to soft delete resource (lets say - a blog post). Actual marking of post as deleted is the easy part. You just need to customize the form:&lt;/p&gt;

&lt;pre&gt;
# app/admin/blog_posts.rb
form do |f|
...
  f.input :is_deleted, :label =&gt; 'Mark as deleted'
...
end
&lt;/pre&gt;


&lt;p&gt;Then you have to hide those posts, right? The easiest way was to use a &lt;a href="http://apidock.com/rails/ActiveRecord/Base/default_scope/class"&gt;default scope&lt;/a&gt;.&lt;/p&gt;

&lt;pre&gt;
# app/models/blog_post.rb
class BlogPost &lt; ActiveRecord::Base
  default_scope where(:is_deleted =&gt; :false)
end
&lt;/pre&gt;


&lt;p&gt;Cool! But now all those "deleted" posts are hidden for admins too. Not cool...
I couldn't find anything about that in the docs, so I took a look at the source code. First good candidate was &lt;a href="https://github.com/gregbell/active_admin/blob/master/lib/active_admin/resource_controller/collection.rb"&gt;scoped_collection&lt;/a&gt;, but it's comments explicitly say&lt;/p&gt;

&lt;blockquote&gt;&lt;p&gt;"Note, unless you are doing something special, you should use the scope_to method from the Scoping module instead of overriding this method."&lt;/p&gt;&lt;/blockquote&gt;

&lt;p&gt;&lt;a href="https://github.com/gregbell/active_admin/blob/master/lib/active_admin/resource_controller/scoping.rb#L10-24"&gt;Here's&lt;/a&gt; what I've found about that mysterious config option named scope_to.&lt;/p&gt;

&lt;p&gt;This was my first attempt:&lt;/p&gt;

&lt;pre&gt;
ActiveAdmin.register BlogPost do
...
  scope_to Proc.new { BlogPost.unscoped }
...
end
&lt;/pre&gt;


&lt;p&gt;That was throwing an error saying&lt;/p&gt;

&lt;blockquote&gt;&lt;p&gt;undefined method `blog_posts' for #&amp;lt;ActiveRecord::Relation:0xb511be48&gt;&lt;/p&gt;&lt;/blockquote&gt;

&lt;p&gt;Obviously whatever scope_to returns have to respond to &lt;strong&gt;:blog_posts&lt;/strong&gt; (plural form for your resource).
Next I've tried&lt;/p&gt;

&lt;pre&gt;
ActiveAdmin.register BlogPost do
...
  scope_to do
    Class.new do
      def self.blog_posts
        BlogPost.unscoped
      end
    end
  end
...
end
&lt;/pre&gt;


&lt;p&gt;Yay! It worked.&lt;/p&gt;

&lt;p&gt;Actually there's other way too - you can add your own &lt;strong&gt;Admin:BlogPostsController&lt;/strong&gt;, define your method there and pass it's name as symbol to scope_to. For now I prefer to keep all ActiveAdmin related stuff at one file per resource.&lt;/p&gt;

&lt;p&gt;Is there better way to do that? Please drop a comment if you know one.&lt;/p&gt;
</content>
    <summary type="html">How to scope resources using scope_to - neat but not yet fully documented config option.</summary>
  </entry>
  <entry>
    <id>tag:blog.codingspree.net,2011-06-06:/2011/06/06/restart.html</id>
    <title type="html">Restart</title>
    <published>2011-06-05T21:00:00Z</published>
    <updated>2011-06-06T07:55:54Z</updated>
    <link rel="alternate" href="http://blog.codingspree.net/2011/06/06/restart.html"/>
    <content type="html">&lt;p&gt;Lets give this blog a try once again.&lt;/p&gt;

&lt;p&gt;This time I'm going to use &lt;a href="http://nanoc.stoneship.org"&gt;nanoc&lt;/a&gt; and &lt;a href="https://github.com/mgutz/nanoc3_blog"&gt;nanoc3_blog&lt;/a&gt;. It looks like simple and easy solution, exactly what I actually need.&lt;/p&gt;

&lt;p&gt;Stay tuned!&lt;/p&gt;
</content>
    <summary type="html">A new hope for my dev blog, this time with some help from nanoc</summary>
  </entry>
</feed>

