Articles

Follow-up on my presentation on JRuby

Me, gesticulating vehemently I’m very pleased!

Jumping to Specific Windows in Emacs

OK, last emacs tip for a while. It’s ironic, but the last two years I’ve written some cool elisp while at RubyConf. I typically run emacs full screen and split buffers both vertically and horizontally to arrange bits of code. It’s not uncommon for me to end up with three, four, five or even six visible windows in emacs. The problem though is navigating between them.

Sharing the Mac Clipboard with Emacs

While I’m sharing emacs hacks, I finally got around to researching this and/or figuring it out. I almost always run emacs inside the terminal in a “no window” mode. It’s pretty natural for me to use M-w to copy something from emacs and then try to Cmd-V it in another Terminal window or likewise Cmd-C something in Terminal and then try paste it into emacs with C-y. Until now, I haven’t known how to share the clipboard with emacs.

Navigating Your Projects in Emacs

One of the things that’s really nice about TextMate is the Cmd-T navigation of files in your project. It pops up this little dialog with fancy pattern matching input to select one of the files in your project and then jumps to that file. There’s a similar command once your in a file to jump to symbols in that file. I’ve tried a couple things to achieve that behavior in emacs that I’d like to talk about.

Why I moved from Prototype to jQuery

Mat mini

Good news everyone*!

Tomorrow my presentation at
Montreal on Rails is going to be made on my brand new Mac Mini!

In my last post I mentioned I was going to present on an ooooold Win XP laptop, but I decided to make the switch to the Mac world now. Well, one week ago. So fear not, I’m not going to subject our community to a 5 square meters XP/Powerpoint eye bleeding festival.

Ruby.framework

A few articles ago I talked about re-building Ruby on Leopard (instead of using the provided Ruby.framework).

A couple days ago, I switched back to the framework to play around and have been using it instead – and after Laurent’s talk tonight I’m 100% certain it was the right decision.

Absolutely amazing.

Javascript + embedded Ruby templates with Rails, out-of-the-box

I recently tried using Dan Webb’s MinusMOR plugin, which allows you to write Javascript templates with embedded Ruby (a la .html.erb/.rhtml templates), but I was disappointed to find out it didn’t work with Edge Rails.
I found a random Pastie via Google that seemed to fix the plugin for Edge, and this worked okay, with the [...]

Drinks at RubyConf

My employer and BlueBox Group are graciously holding the bar open at Arpa after the RubyConf keynote. Obviously they’ll cap us at some point… but let’s make that happen, shall we?

No agenda + free drinks. See the official announcement and réservez s ‘il-vous-plaît if you have a moment (so I can gauge my planned intake).

Stackalicious

So, at the risk of making entirely too many posts about Leopard today, I’m going to toss another out.

Uses for Stacks:

* Clean up messes: Within a week I can turn a nice, clean desktop into a morass of inane downloads, screenshots, and documents. A Stack of ~/Downloads makes things a lot cleaner. If I can only figure out how to get screenshots to go into a separate Stack…

Rails Caching: Dynamic Fragments | Rails Fire

Rails Caching: Dynamic Fragments

I am finally getting around to implementing caching on my Rails application that I’ve been working on adamantly for the past couple of months.  For the time being, I am using a memcached server with simple action and page caching.  I ran into a few problems with my first few attempts at fragment caching and decided it wasn’t really necessary for the time being.  I needed a simple method of including small sections of dynamic code in an otherwise static page.  I then wanted to use action caching on the resulting view.  I’ll outline a simple method I used to achieve this.

I’ve been very happy with the results.  Very server intense requests are responding instantly.  This is all great, but caching is usually only appropriate for pages with content that is static for a period of time.  The biggest problem I was having is that there are very small pieces of the pages I wished to cache that are dynamic.  For instance, I want to have a bar at the top that tells the user who is logged in and provides a set of buttons to do things to their profile, etc.  An example of this is shown below:

Small Dynamic Block Showing User Profile Links

Small Dynamic Block Showing User Profile Links

So what I needed was an easy way to specify that this small block would be dynamic while still allowing the rest of the view to take advantage of action caching.  I’m sure there is some plugin that does this and more.  If there is a very good plugin that does just this, I would love to know about it in the comments.  For now, though I am going to provide my simple solution to the problem.

My solution was to create a partial for the profile summary.  I already had the block as a partial to make my view code more DRY.  Instead of this:

<%=render :partial => 'profile_summary'%>

in my view, I replaced it with an AJAX call using Prototype (updated to use Richard Poirier’s suggestion in the comments):

    
<%= javascript_tag remote_function(:url => { :controller => 'profile', :action => 'summary' }) %>

I then have a controller that can repond to this AJAX request for the profile.

def summary
  render :update do |page|
    page.replace_html 'info_panel', :partial => '/profile/summary'
  end
end

Now, every time the page loads, it will load the entire page using the cached version.  It will then make an additional POST request to get the dymanic content.  This would become more complicated if there were many dynamic sections that I needed to load.  I feel like if it was wrapped into a plugin that could automatically handle special dynamic fragments inside a block like this:

<%=dynamic_fragment do%>
   <%=render :partial => 'profile_summary'%>
<%end%>

it would make it very easy and intuitive to insert dynamic fragments into an otherwise static page.  I do not have the need to implement something like this yet, I am satisfied with my simple solution.  I would be very happy to find a solution where you can specify the dynamic sections of the view instead of only specifying the static portions.  Then the system would magically build the server-side AJAX responses without the user having to do anything.  This allows the use of action_caches which are supposed to be much faster than fragment caching.  While I’m super busy with my project, stopping to create plugins is not on the priority list, but by writing it all down here I might come back to the best ideas.

I hope anybody looking to insert a small section of dynamic code in an otherwise action cacheable page finds this information useful.

Chase

Images: