Today I continued work on my Syntag application, trying to learn more about how Ruby on Rails and web development in general work. I learned about how you can use JavaScript to do web requests and inject them into your pages (AJAX). This technique turns out to be very, very powerful. With these few lines of coffeescript code (by the way, I learned a little coffeescript along the way! Maybe I’ll do a post on that when I know more about it), I can make my application not require a refresh for a user to view a snippet from the Syntag database:

$.ajax(url: "/snippets/" +
    $("#snippet_select").val() + ".json").done((json_snip) ->
		$.ajax(url: "/admin/languages/" + json_snip['language_id'] + '.json').done((json_lang) ->
			$("#snippet").addClass("lang-" + json_lang['highlighter_name'])))

Honestly, I think this syntax is kinda silly and kludgey, but maybe it’ll grow on me. It seems to be the current hot thing in the computer science community. While I was writing this blog post I made the change of setting the text of the snippet div to the contents of the snippet.

The next thing that I want to work on is syntax highlighting in that interface and then prettying it up a little. Allons-y!