Development Headquarters

A Complete Guide to Passenger Sub URI Configuration

I wanted to use Passenger's RailsBaseURI capability so I could simplify managing the server during development. With Passenger installed on my laptop, there's no more extra web services to start and stop, no more fretting over service ports. And with RailsBaseURI sub-URIs there are nice logically mapped URIs that match my development directories (~/Developer/Rails/railsproj1 => http://localhost/railsproj1, ~/Developer/Rails/railsproj2 => http://localhost/railsproj2, etc.).

It couldn't get sweeter, but sometimes Passenger doesn't work as advertised (not to worry, it's intense development activity compensates). After following Phusion's directions I was getting a 404 not found error. Then I found the solution at Aschan's blog. So here's a complete (for the moment) guide:

1. Create the symlink from the Rails project's public folder to a location under your document root. I used the ~/Sites folder as my document root. In it, I made the symlink to my Rails project's public folder, like:

cd ~/Sites
ln -s /Users/hg/Developer/Rails/railsproj1/public ./railsproj1
2. Configure the Apache conf file. I edited /etc/apache2/users/hg.conf: (I've bolded the parts worth noting.)
<VirtualHost *:80>
  ServerName localhost
  DocumentRoot /Users/hg/Sites
  <Directory /Users/hg/Sites>
    AllowOverride All
    Options Indexes FollowSymLinks MultiViews
    Order allow,deny
    Allow from all
  </Directory>
  RailsBaseURI /railsproj1
  RailsEnv development
</VirtualHost>
3. So far, this won't work, although Phusion claims it does. Next add this line (courtesy of Ashchan's blog) in your Rails project's environment.rb file:
config.action_controller.relative_url_root = "/railsproj1"

Restart Apache and you should be good to go.  Let me know if you have anything to add.

0 comments

Using the Controllers/Actions Generator to Populate a Rights Table

The controllers/actions generating script is coming in very useful.  I'm just getting my feet wet with it, but here it is in a migration I use to populate a Rights table (which I use for a 'Rails Recipes'-style user/roles architecture:

require 'find'
class PopulateRights < ActiveRecord::Migration
  def self.up
    controller_directory = "#{RAILS_ROOT}/app/controllers/"
    controller_files = []
    controllers_and_actions = []
    Find.find(controller_directory) do |node|
      if FileTest.file?(node)
        controller_files << node.gsub("#{controller_directory}","")
      end
    end
    controller_files.each do |controller_file|
      if controller_file =~ /_controller/
        controller_path = controller_file.gsub("_controller.rb","")
        controller = controller_file.camelize.gsub(".rb","").gsub("/","::")
        actions = []
        (eval("#{controller}.new.methods") - (ApplicationController.methods + Object.methods + ApplicationController.new.methods - ["new"])).sort.each do |action|
          actions << action
        end
        controllers_and_actions << { :controller_path => controller_path, :actions => actions }
      end
    end
    controllers_and_actions.each do |controller_actions|
      controller_actions[:actions].each do |action|
        Right.create(:name => action.titlecase + ' ' + controller_actions[:controller_path].titlecase, :controller => controller_actions[:controller_path], :action => action)
      end
    end
  end

  def self.down
    Right.find(:all).each do |right|
      right.destroy
    end
  end
end

0 comments

Generating Rails Controllers and Actions

Here's a useful script to run in the console.  It produces a list of controllers and actions based on the controller files in your project:

require 'find'
controller_directory = "#{RAILS_ROOT}/app/controllers/"
controller_files = []
Find.find(controller_directory) do |node|
  if FileTest.file?(node)
    controller_files << node.gsub("#{controller_directory}","")
  end
end
controller_files.each do |controller_file|
  if controller_file =~ /_controller/
    controller = controller_file.camelize.gsub(".rb","").gsub("/","::")
    puts controller
    (eval("#{controller}.new.methods") - (ApplicationController.methods + Object.methods + ApplicationController.new.methods - ["new"])).sort.each do |action|
      puts "\t#{action}"
    end
  end
end

0 comments

Listing request.env variables

Don't need to roll by hand the 'handy snippet' any longer, you get the same info, appearing nicer, using:

<%= debug(request.env) %>
Here's a handy snippet for printing the contents of the requent.env hash:
<table>
  <tr>
    <th>key</th>
    <th>value</th>
  </tr>
  <% for item in request.env %>
    <tr><td><%= item[0] %></td><td><%= item[1] %></td></tr>
  <% end %>
</table>

0 comments

Radiant Extension Ideas

These are Radiant extensions I'd like to see:

Asset Archive Page Type

I like the fact that page_attachments associates assets with a page. (I also like that it uses attachment_fu, for stability reasons.) It would be nice to have a new page type called, say 'Asset Archive'. You could create 'Asset Archives' with familiar names, such as: 'Files' or 'Images'. Also, this extension would add tags, shortening the syntax for retrieving assets, something like:

<r:asset:image from='/files' name='coolpic.jpg'/>

Pagination

This maybe already exists.  But an extension using will_paginate would be welcome.

Parts iterator tags

  • <r:parts>...</r:parts>
  • <r:parts:count />
  • <r:parts:each [matches='regexp' | by='attribute' ]> ... </r:parts:each>
    • attributes means columns of the page_parts table.  New attributes would be added 'description' and 'keywords'

Link assets

In page editing:

  • Links would appear as an enhancement to the markup input filters (Markdown, SmartyPants, Textile)
  • A site map of links would be compiled and listed
  • The site map of links would include the title of the last child node and the concatenation of slugs leading up to it
  • Additional links would be available that were created in the administrative interface
In page list:
  • An administrative Links tab would be added
    • The site map of links be read-only viewable (maybe additional attributes might be editable)
    • Additional links could be added and removed
    • Attributes for additional links would include: name, description, url

0 comments

Rating Radiant Extensions

Here are my de Tocquevillian impressions of Radiant extensions so far.  I'm only rating the ones that interest me.

(I'll be explaining the grading system later.) 

page_attachment - A

sphinx_search - F

reorder - A

paperclipped - A

copy_move - A

0 comments

Installing a Radiant Extension

Here are a couple of ways of installing a Radiant extension.  It's the page_attachments extension.

Method 1 - The new way

(in your project directory)

cd ~/my/radiant/project/directory
script/extension install page_attachments

Method 2 - The manual way

If installing the extension on a per-project basis, then do:

(as project owner)

cd ~/my/radiant/project/directory
git clone git://github.com/radiant/radiant-page-attachments-extension.git vendor/extensions/page_attachments
rake radiant:extensions:page_attachments:migrate RAILS_ENV=production
rake radiant:extensions:page_attachments:update RAILS_ENV=production

If installing the extension for all projects, then do:

(as root)

cd /Library/Ruby/Gems/1.8/gems/radiant-0.6.9
git clone git://github.com/radiant/radiant-page-attachments-extension.git vendor/extensions/page_attachments

(as project owner)

cd ~/my/radiant/project/directory
git clone git://github.com/radiant/radiant-page-attachments-extension.git vendor/extensions/page_attachments
rake radiant:extensions:page_attachments:migrate RAILS_ENV=production
rake radiant:extensions:page_attachments:update RAILS_ENV=production

0 comments

Radius Tags

We've started learning the Radius tagging language used in Radiant CMS.  Although the language's complete documentation is readily available from Radiant's page editing interface (as a HUD-style Javascript window), I haven't found this documentation anywhere else on the internet yet.  That is, until now.

<r:page></r:page>
    Causes the tags referring to a page's attributes to refer to the current page.

    Usage:
    <pre><code><r:page>...</r:page></code></pre>
  
<r:breadcrumb/>
<r:slug/>
<r:title/>
<r:url/>
      Renders these attributes of the current page.

<r:children></r:children>
    Gives access to a page's children.

    Usage:
    <pre><code><r:children>...</r:children></code></pre>
  
<r:children:count/>
    Renders the total number of children.
 
<r:children:first></r:children:first>
    Returns the first child. Inside this tag all page attribute tags are mapped to
    the first child. Takes the same ordering options as <r:children:each>.

    Usage:
    <pre><code><r:children:first>...</r:children:first></code></pre>

<r:children:last></r:children:last>
    Returns the last child. Inside this tag all page attribute tags are mapped to
    the last child. Takes the same ordering options as <r:children:each>.

    Usage:
    <pre><code><r:children:last>...</r:children:last></code></pre>

<r:children:each></r:children:each>
    Cycles through each of the children. Inside this tag all page attribute tags
    are mapped to the current child page.

    Usage:
    <pre><code><r:children:each [offset="number"] [limit="number"] [by="attribute"] [order="asc|desc"] [status="draft|reviewed|published|hidden|all"]>
     ...
    </r:children:each>
    </code></pre>

<r:child></r:child>
    Page attribute tags inside of this tag refer to the current child. This is occasionally
    useful if you are inside of another tag (like <r:find>) and need to refer back to the
    current child.

    Usage:
    <pre><code><r:children:each>
      <r:child>...</r:child>
    </r:children:each>
    </code></pre>

<r:header></r:header>
    Renders the tag contents only if the contents do not match the previous header. This
    is extremely useful for rendering date headers for a list of child pages.
    
    If you would like to use several header blocks you may use the name attribute to
    name the header. When a header is named it will not restart until another header of
    the same name is different.
    
    Using the restart attribute you can cause other named headers to restart when the
    present header changes. Simply specify the names of the other headers in a semicolon
    separated list.

    Usage:
    <pre><code><r:children:each>
      <r:header [name="header_name"] [restart="name1[;name2;...]"]>
        ...
      </r:header>
    </r:children:each>
    </code></pre>

<r:parent></r:parent>
    Page attribute tags inside this tag refer to the parent of the current page.

    Usage:
    <pre><code><r:parent>...</r:parent></code></pre>
  
<r:if_parent></r:if_parent>
    Renders the contained elements only if the current contextual page has a parent, i.e. 
    is not the root page.

    Usage:
    <pre><code><r:if_parent>...</r:if_parent></code></pre>

<r:unless_parent></r:unless_parent>
    Renders the contained elements only if the current contextual page has no parent, i.e. 
    is the root page.

    Usage:
    <pre><code><r:unless_parent>...</r:unless_parent></code></pre>

<r:if_children></r:if_children>
    Renders the contained elements only if the current contextual page has one or
    more child pages.  The status attribute limits the status of found child pages
    to the given status, the default is "published". status="all" includes all
    non-virtual pages regardless of status.

    Usage:
    <pre><code><r:if_children [status="published"]>...</r:if_children></code></pre>

<r:unless_children></r:unless_children>
    Renders the contained elements only if the current contextual page has no children.
    The status attribute limits the status of found child pages to the given status,
    the default is "published". status="all" includes all non-virtual pages 
    regardless of status.

    Usage:
    <pre><code><r:unless_children [status="published"]>...</r:unless_children></code></pre>

<r:cycle/>
    Renders one of the passed values based on a global cycle counter.  Use the reset
    attribute to reset the cycle to the beginning.  Use the name attribute to track 
    multiple cycles; the default is cycle.

    Usage:
    <pre><code><r:cycle values="first, second, third" [reset="true|false"] [name="cycle"] /></code></pre>

<r:content/>
    Renders the main content of a page. Use the part attribute to select a specific
    page part. By default the part attribute is set to body. Use the inherit
    attribute to specify that if a page does not have a content part by that name that
    the tag should render the parent's content part. By default inherit is set to
    false. Use the contextual attribute to force a part inherited from a parent
    part to be evaluated in the context of the child page. By default 'contextual'
    is set to true.

    Usage:
    <pre><code><r:content [part="part_name"] [inherit="true|false"] [contextual="true|false"] /></code></pre>

<r:if_content></r:if_content>
    Renders the containing elements if all of the listed parts exist on a page.
    By default the part attribute is set to body, but you may list more than one
    part by separating them with a comma. Setting the optional inherit to true will 
    search ancestors independently for each part. By default inherit is set to false.
    
    When listing more than one part, you may optionally set the find attribute to any
    so that it will render the containing elements if any of the listed parts are found.
    By default the find attribute is set to all.

    Usage:
    <pre><code><r:if_content [part="part_name, other_part"] [inherit="true"] [find="any"]>...</r:if_content></code></pre>
  
<r:unless_content></r:unless_content>
    The opposite of the if_content tag. It renders the contained elements if all of the 
    specified parts do not exist. Setting the optional inherit to true will search 
    ancestors independently for each part. By default inherit is set to false.
    
    When listing more than one part, you may optionally set the find attribute to any
    so that it will not render the containing elements if any of the listed parts are found.
    By default the find attribute is set to all.
    
    Usage:
    <pre><code><r:unless_content [part="part_name, other_part"] [inherit="false"] [find="any"]>...</r:unless_content></code></pre>
  
<r:if_url></r:if_url>
    Renders the containing elements only if the page's url matches the regular expression
    given in the matches attribute. If the ignore_case attribute is set to false, the
    match is case sensitive. By default, ignore_case is set to true.
    
    Usage:
    <pre><code><r:if_url matches="regexp" [ignore_case="true|false"]>...</if_url></code></pre>
  
<r:unless_url></r:unless_url>
    The opposite of the if_url tag.
    
    Usage:
    <pre><code><r:unless_url matches="regexp" [ignore_case="true|false"]>...</unless_url></code></pre>

<r:if_ancestor_or_self></r:if_ancestor_or_self>
    Renders the contained elements if the current contextual page is either the actual page or one of its parents.
    
    This is typically used inside another tag (like <r:children:each>) to add conditional mark-up if the child element is or descends from the current page.
    
    Usage:
    <pre><code><r:if_ancestor_or_self>...</if_ancestor_or_self></code></pre>
  
<r:unless_ancestor_or_self></r:unless_ancestor_or_self>
    Renders the contained elements unless the current contextual page is either the actual page or one of its parents.
    
    This is typically used inside another tag (like <r:children:each>) to add conditional mark-up unless the child element is or descends from the current page.
    
    Usage:
    <pre><code><r:unless_ancestor_or_self>...</unless_ancestor_or_self></code></pre>
  
<r:if_self></r:if_self>
    Renders the contained elements if the current contextual page is also the actual page.
    
    This is typically used inside another tag (like <r:children:each>) to add conditional mark-up if the child element is the current page.
    
    Usage:
    <pre><code><r:if_self>...</if_self></code></pre>
  
<r:unless_self></r:unless_self>
    Renders the contained elements unless the current contextual page is also the actual page.
    
    This is typically used inside another tag (like <r:children:each>) to add conditional mark-up unless the child element is the current page.
    
    Usage:
    <pre><code><r:unless_self>...</unless_self></code></pre>
  
<r:author/>
    Renders the name of the author of the current page.
  
<r:date/>
    Renders the date based on the current page (by default when it was published or created). 
    The format attribute uses the same formating codes used by the Ruby strftime function. By
    default it's set to %A, %B %d, %Y.  The for attribute selects which date to render.  Valid
    options are published_at, created_at, updated_at, and now. now will render the
    current date/time, regardless of the  page.
    
    Usage:
    <pre><code><r:date [format="%A, %B %d, %Y"] [for="published_at"]/></code></pre>

<r:link/> | <r:link></r:link>
    Renders a link to the page. When used as a single tag it uses the page's title
    for the link name. When used as a double tag the part in between both tags will
    be used as the link text. The link tag passes all attributes over to the HTML
    a tag. This is very useful for passing attributes like the class attribute
    or id attribute. If the anchor attribute is passed to the tag it will
    append a pound sign (<code>#</code>) followed by the value of the attribute to
    the href attribute of the HTML a tag--effectively making an HTML anchor.
    
    Usage:
    <pre><code><r:link [anchor="name"] [other attributes...] /></code></pre>
    or
    <pre><code><r:link [anchor="name"] [other attributes...]>link text here</r:link></code></pre>
  
<r:breadcrumbs/>
    Renders a trail of breadcrumbs to the current page. The separator attribute
    specifies the HTML fragment that is inserted between each of the breadcrumbs. By
    default it is set to >. The boolean nolinks attribute can be specified to render
    breadcrumbs in plain text, without any links (useful when generating title tag).
    
    Usage:
    <pre><code><r:breadcrumbs [separator="separator_string"] [nolinks="true"] /></code></pre>

<r:snippet/>
    Renders the snippet specified in the name attribute within the context of a page.
    
    Usage:
    <pre><code><r:snippet name="snippet_name" /></code></pre>
    
    When used as a double tag, the part in between both tags may be used within the
    snippet itself, being substituted in place of <r:yield/>
    
    Usage:
    <pre><code><r:snippet name="snippet_name">Lorem ipsum dolor...</r:snippet></code></pre>

<r:yield/>
    Used within a snippet as a placeholder for substitution of child content, when 
    the snippet is called as a double tag.
    
    Usage (within a snippet):
    <pre><code>
    <div id="outer">
      <p>before</p>
      <r:yield/>
      <p>after</p>
    </div>
    </code></pre>
    
    If the above snippet was named "yielding", you could call it from any Page, 
    Layout or Snippet as follows:
    
    <pre><code><r:snippet name="yielding">Content within</r:snippet></code></pre>
    
    Which would output the following:
    
    <pre><code>
    <div id="outer">
      <p>before</p>
      Content within
      <p>after</p>
    </div>
    </code></pre>
    
    When called in the context of a Page or a Layout, <r:yield/> outputs nothing.
  
<r:find></r:find>
    Inside this tag all page related tags refer to the page found at the url attribute.  
    urls may be relative or absolute paths.
    
    Usage:
    <pre><code><r:find url="value_to_find">...</r:find></code></pre>
  
<r:random><r:option></r:option></r:random>
    Randomly renders one of the options specified by the option tags.
    
    Usage:
    <pre><code><r:random>
      <r:option>...</r:option>
      <r:option>...</r:option>
      ...
    <r:random>
    </code></pre>
  
<r:comment></r:comment>
    Nothing inside a set of comment tags is rendered.
    
    Usage:
    <pre><code><r:comment>...</r:comment></code></pre>
  
<r:escape_html></r:escape_html>
    Escapes angle brackets, etc. for rendering in an HTML document.
    
    Usage:
    <pre><code><r:escape_html>...</r:escape_html></code></pre>
  
<r:rfc1123_date/>
    Outputs the published date using the format mandated by RFC 1123. (Ideal for RSS feeds.)
    
    Usage:
    <pre><code><r:rfc1123_date /></code></pre>
  
<r:navigation></r:navigation>
    Renders a list of links specified in the urls attribute according to three
    states:
    
    * normal specifies the normal state for the link
    * here specifies the state of the link when the url matches the current
       page's URL
    * selected specifies the state of the link when the current page matches
       is a child of the specified url
    
    The between tag specifies what should be inserted in between each of the links.
    
    Usage:
    <pre><code><r:navigation urls="[Title: url | Title: url | ...]">
      <r:normal><a href="<r:url />"><r:title /></a></r:normal>
      <r:here><strong><r:title /></strong></r:here>
      <r:selected><strong><a href="<r:url />"><r:title /></a></strong></r:selected>
      <r:between> | </r:between>
    </r:navigation>
    </code></pre>
   
<r:if_dev></r:if_dev>
    Renders the containing elements only if Radiant in is development mode.
    
    Usage:
    <pre><code><r:if_dev>...</r:if_dev></code></pre>
  
<r:unless_dev></r:unless_dev>
    The opposite of the if_dev tag.
    
    Usage:
    <pre><code><r:unless_dev>...</r:unless_dev></code></pre>
  
<r:status/>
    Prints the page's status as a string.  Optional attribute 'downcase
    will cause the status to be all lowercase.
    
    Usage:
    <pre><code><r:status [downcase='true'] /></code></pre>
  
<r:meta/> | <r:meta></r:meta>
    The namespace for 'meta' attributes.  If used as a singleton tag, both the description
    and keywords fields will be output as <meta />; tags unless the attribute 'tag' is set to 'false'.
    
    Usage:
    <pre><code><r:meta [tag="false"] /> 
     <r:meta>
       <r:description [tag="false"] />
       <r:keywords [tag="false"] />
     </r:meta>
    </code></pre>
  
<r:meta:description/>
    Emits the page description field in a meta tag, unless attribute
    'tag' is set to 'false'.
    
    Usage:
    <pre><code><r:meta:description [tag="false"] /></code></pre>

<r:meta:keywords/>
    Emits the page keywords field in a meta tag, unless attribute
    'tag' is set to 'false'.
 
    Usage:
    <pre><code><r:meta:keywords [tag="false"] /></code></pre>

0 comments

Leopard Server Collaboration Services Kind of Worked Out

Well the Leopard Server group collaboration applications are now working for the most part.

The problems stemmed from not reading every document explaining the requirements.  The requirements are distributed across three documents: "Web Technologies", "Open Directory Administration" and "iCal Service Administration".  I had focused on the later document only.  Silly me.  Also, confusion arose from incomplete documentation.  For instance, it's not mentioned anywhere that iCal Server has the same requirements as wiki server.  As soon as I applied the required configurations for wiki, the iCal Server started working as well.

I found in 'Web Technologies' that the wiki server must host its own Open Directory master domain...

"Wiki will not work without a local Open Directory master. Your server can be connected to another directory server simultaneously, but for wiki to work, your server must be an Open Directory master. For more information, see Open Directory Administration."

From Web Technologies, page 64


My scenario for setting this up was fortuitous since...

"If Mac OS X Server was connected to a directory system and you make the server an Open Directory master, it remains connected to the other directory system. The server will search for user records and other information in its shared LDAP directory domain before searching in other directory systems it is connected to."


So I was closer to completing the task than I thought.  I just had to promote the collaboration server to an OD master.

My anxiety about hosting two OD masters was based on not knowing what Workgroup Manager would do to manage UID and GID conflicts and the possibility that I'd have to manage them manually.  That would be a burden especially at the file system level of a shared web service.  But Leopard's Workgroup Manager prevents collisions from occurring.  It doesn't let you use ids that already exist in another domain. That was a big relief.

Bugs still persist.  Subscribing to iCal calendars produces a 401 HTTP error.  Also, after rebooting the server I've found that the individual blogs disappear only to reappear after I've made some change through Server Admin.  I haven't found the steps that reproduce the fix yet.


0 comments

Leopard Server Collaboration Services

Today I started setting up Leopard Server collaboration services.

So far, alas, I've found the services to be buggy or poorly documented.  The blog service is working as evidenced here, but the iCal and wiki services are not yet working.

I can't say yet where the problem is stemming: from the immaturity of the software, from incomplete LDAP attributes, or from corrupted plist files.  Actually it all points to immature software.  I'm reading that people are getting these services working, but I suspect the execution has to be in a particular sequence in order for it to succeed.  In our situation, we're migrating existing services, a scenario I suspect these new services weren't fully tested against.

Here's the situation.  I can see the groups and users from the web server hosting the collaboration services.  (That makes sense since the web server is bound to the open directory server.)  But from the directory server point-of-view the web server and its services do not appear listed in the 'Enable the following services for this group' list.  I don't think the collaboration services are dynamically discovered by the open directory server.  My hunch is that an LDAP record for the web server is missing here.

No doubt these issues will be ironed out and I'll become versed in the Python-based systems that underpin them along the way.  This blogging system rocks, which keeps me hopeful that the effort in getting it all working will be worth it.

0 comments