Posted by & filed under Developer Blog.

After much trial and error, and frustration, I have finally come up with what I believe is the best possible way to do multiple select combo boxes in Rails. It’s not so much that there aren’t examples on the web, it’s just that every example is so different. I’ve used what I feel is the best from each example and created this example.

First, it’s best that the options are in an array somewhere. In this example, we’ll assume that all states are set in an array on the application.rb and the array is named $states

In the _form, or wherever your form is, do the following:

<% if @model_name and @model_name.states
@states_selected = @model_name.states.collect
end %>
<label for="model_name_states">State</label><br/>
<%= select_tag 'model_name[states][]', options_for_select($states, @states_selected), { :multiple => true, :size =>5, :id => "model_name_states" } %></p>

This will not only dynamically create your select field with each option, but it will make it so that if someone leaves off a required field the same selected states will be selected on the edit screen!

See the Rails documentation for options_for_select to customize it even further. Obviously you can leave off the :multiple and :size to make it a single select with similar results, but it’s better to use select instead of select_tag for single select combo boxes.

Posted by & filed under Developer Blog.

RubyWeaver is an IDE for Ruby and Rails in Dreamweaver. This extension originally came from RidingTheClutch.com which seems to have mysteriously disappeared, along with it’s original author Rob Cameron whom I have tried to contact with regards to RubyWeaver, but with no avail. I’ve taken the liberty to make this extension available once again to those who are looking for it, which I believe to be many. Since Macromedia (Adobe) makes it very easy to retrieve the source code for an extension once it is installed, I’ve also taken the liberty of upgrading it a bit, since I have built a dreamweaver extension similar to this one before and thought everyone could benefit from the enhancements.

If you do any Ruby on Rails and want to use it with Dreamweaver, Download RubyWeaver 2.0 today!

Posted by & filed under Developer Blog.

I don’t know if it’s because the Lucid theme for Mephisto was ported from Typo, but it was displaying the timestamp on my entries as UTC instead of MST, which is what I told Mephisto my time zone is in the Settings. Apparently Lucid uses JavaScript to convert the timestamp into a more descriptive time (“about an hour ago”) if the timestamp is less than a week old and otherwise displays the date.

Without having enough time to really look into it, I believe Mephisto is using TZinfo Gem to convert the database timestamp to whatever you set your timezone to be in the Settings and Lucid is reading that as UTC anyway and attempting to convert it to the users current time.

So rather that fudging the JavaScript, I decided to reformat the date that Lucid sees and let it do it’s thing. In other words, I plugged the following into the home.liquid, index.liquid, and single.liquid templates:

from

<p class="auth">Posted 
<span class="typo_date" title="{{ article.published_at }}">
{{ article.published_at }}
</span></p>

to

<p class="auth">Posted
<span class="typo_date" title="{{ article.published_at | date: "%a %b %d %H:%M:%S MST %Y" }}">
{{ article.published_at | date: "%a %b %d %H:%M:%S MST %Y" }}
</span></p>

where MST is my own time zone.

Hope this helps others, as I wasn’t able to find any other info about it.

Posted by & filed under Developer Blog.

For a minute, I thought my comments were not working or were being blocked on this site. I could post one comment, but anything after that didn’t work. I spent most of the morning trying to figure out why it was happening and thinking I’d broken something while tweaking my theme or something. I also wondered if it was some type of built in spam protection that I didn’t know about.

Then, as I was browsing through the Mephisto Wiki I stumbled upon the answer. The problem was stemming from the fact that I’m running Mephisto on Apache. According to the wiki entry I found, it’s because Apache likes to add a trailing slash (/) to anything without an extension (stuff that follows the dot “.” in a filename) thinking that it must be a directory. Rails urls (and therefore Mephisto urls) use Pretty Urls instead of extensions and the like.

Apparently, however Mephisto is handling comments is being cached weird in Apache because of it. The easiest, and highly effective, solution is to plug the following in your public/.htaccess file somewhere (I put it at the bottom):
DirectorySlash Off
Since it took me 4 hours to find that post with the answer, I thought I’d post it here as well and hopefully those looking for a solution can find it in one of the two places quicker.