18 Jun 2009, 5:07pm
Songwriting
by

2 comments

You Know My Way

You Know My Way
by Sean Behan

[podcast]http://seanbehan.com/wp-content/uploads/2009/06/01-You-Know-My-Way-MP3.mp3[/podcast]

How to Use Pretty URLs with Rails will_paginate Plugin

The will_paginate plugin for Rails uses a key/value assignment like ?page=2, rather than the pretty url formats such as /page/2 … This is because url generation and mapping are handled by the routes.rb file. You’ll need to modify the file so that rails knows what to do with request that match the pattern. Make sure to put the custom (map.connect) route before the normal restful routes (map.resources)

map.connect '/topics/:id/page/:page', :controller => 'topics', :action => 'show'
map.resources :topics

Internally will_paginate uses the url_for method so Rails will now know how to construct your urls in a pretty way. I got most of this info from this discusson http://groups.google.com/group/will_paginate/browse_thread/thread/d0142b512cfca9d5?pli=1

There is nothing wrong leaving the default behavior alone and looking at the ‘ugly’ key/value pairs in the address bar. However, if you take advantage of page caching in rails, you’ll need to do this anyway. Page caching in rails ignore extra parameters, any info before/after the “?” and “&” symbols. There will be no difference from /topics/2?page=1 and /topics/2?page=100 in your cache. And since most likely the content will be very different on these two pages, you’ll need to have pretty urls so that page caching will save topics/2/page/1.html and topics/2/page/100.html as two different resources!

17 Jun 2009, 6:32pm
Photography
by

leave a comment

Using Your Partials in Your Liquid Templates

I’m working on a project that requires users/designers be allowed to edit the layout of their site. I’m using Liquid, Ruby templating system developed by the folks at shopify.com.

Doing a little searching I found this great post http://giantrobots.thoughtbot.com/2008/10/3/custom-tags-in-liquid The liquid documentation itself needs a little more work. But you can check it out here if you want http://wiki.github.com/tobi/liquid/liquid-for-programmers.

I worked through the example at thoughtbot blog and was having trouble with the final step, rendering the partial to the screen. The solution was really a simple step I wasn’t thinking about. Nonetheless, the information for some reason was kept out of the post and burried in the comments.

<%= Liquid::Template.parse(template).render({}, :registers=&gt;{:controller =&gt; controller} %>

Dot htaccess file for wordpress installation (.htaccess)

Login to your wordpress installation and scroll to and click the second to last link set “Settings”. You’ll need to configure wordpress to handle your new links as “permalinks”. Make a selection and copy the code into your .htaccess file. WordPress will attempt to do this for you, but only if your webserver can read/write to the directory.

Permalink Settings

Permalink Settings

Permalink Settings

Permalink Settings

Add the .htaccess file to the root directory of your wordpress installation if wordpress informs you that it can’t get it to work. The file should be named “.htaccess” (w/out quotes).  This is a ‘hidden’ file so if you don’t see it, run the ls -lha command which will list all the files in the directory including hidden files.

Next you’ll want to edit your VirtualHost file. I used the default VirtualHost under /etc/apache2/sites-available/default You’ll need to make one modification to this file. You need to tell it to allow overrides, since we’ll be giving the .htaccess file the right to change configuration options. We need to change the line that says AllowOverrides None to AllowOverrides All

AllowOverrides All

AllowOverrides All