Software and Technology Ramblings

January 14, 2008

Ruby Spreadsheet-Excel gem – 255 character limit

Filed under: Rails — Doug Hays @ 1:28 pm

A client of mine let me know today that the Excel spreadsheets I was generating for them had data truncated at 255 characters. I didn’t find anything on the web that gave a reason or offered a fix so I decided to dig into the code myself. I am using the Ruby Spreadsheet-Excel gem.

Sure enough, on line 289, of workbook.rb (v0.3.5.1), there was this:

      # Truncate strings over 255 characters
      if strlen > StrMax
         str    = str[0..StrMax-1]
         length = 0x0008 + StrMax
         strlen = StrMax
      end

No idea why this was done and I wasn’t going to waste anytime considering the downsides of not truncating, so I commented this block out and it works fine.

Maybe it has something to do with an older version of Excel? Who knows.

December 15, 2007

Integrating FCKEditor and ActiveScaffold

Filed under: Rails — Doug Hays @ 12:35 am

I just solved an issue that I couldn’t find an answer for on the web, so I thought I’d just put it out there so that maybe it could help someone else. I am creating a simple CMS tool for one of my clients and always like to use the FCKEditor for CMS tools. I hadn’t built such a thing in Rails before, nor had I used ActiveScaffold before today. But Rails + ActiveScaffold + FCKEditor seemed like the perfect combination. And it is, once you get it working. Here’s what I had to do to make this work for a table called content_items and a field called content.

After installing the FCKEditor and ActiveScaffold plugins, I created, for the content column, a form column override file in my views/content_items directory called _content_form_column.rhtml. After some trial and error, I landed at this solution:

<%=column.name.to_s.titleize %>:

<%= fckeditor_textarea( :record, column.name, :toolbarSet => 'Simple', :width => '100%', :height => '400px') %>

<input name="commit" type="submit" value="Save" class="submit"
	onClick="var oEditor = FCKeditorAPI.GetInstance('record_<%=@record.id%>_<%=column.name%>_editor');
        document.getElementById('record_<%=@record.id%>_<%=column.name%>_editor').value = oEditor.GetXHTML();" />

Now, this is my 15-minute solution. What I’d like to do is get that onClick JavaScript to fire on the form’s onSubmit event and remove this secondary submit button altogether. But, since it’s late, I decided to remove the ActiveScaffold Update button and make this column the last on the page. How’s that for an I’ll-deal-with-it-later hack!?

Powered by WordPress