I've just released ARID 0.5. This is a minor update with some small bug fixes and optimizations.

ARID ( ActiveResourceIntegrationDsl ) is a Ruby on Rails plugin offering easy to use methods for writing integration tests on RESTful Rails apps. With ARID you write simple statements like user.builds_article(:params => {:article => {:subject => 'Hey!', :content => 'Hello World!'}}) which will GET your new_article_path, check that it has a properly formatted form with fields for all the given params, and then will POST the params to articles_path and assert the expected response. You can even pass a block to the above call to perform additional tests. And YES, ARID tests AJAX calls.

More info and installation instructions at http://arid.rubyforge.org.

Comments: 0 [add comment]

Holy cow, I just blew nearly an entire day trying to fix one stupid little problem with FCKEditor and remote_form_for. Had a lot of trouble finding the right answer online anywhere, so now that I've got it figured out, I'm posting here so hopefully the next person won't have as much trouble as I did.

I was trying to use FCKEditor in one field on a form, and wanted the form to submit to the controller via AJAX, which would respond with an RJS call to update the page. However, I found that when I clicked "Submit", the FCK field in params was blank, BUT if I clicked submit TWICE in a row, the second one sent all the correct data. Apparently, there's a similar problem with ASP.Net and using the RequiredFieldValidator, so all my searches kept leading me to answers to THAT problem, but I ain't using ASP or RequiredFieldValidator.

Eventually, I finally stopped and actually read all of the listings on the FCKEditor Wiki Troubleshooting page and found this post, which exactly described the problem. However, I'm not a big fan of ridiculously vague code with names like MyClass and MyObject... that's just not the Rails way. So... here's my variation on a theme.

First, Add this to your application.js...

var FCKFixer = {
  fixIt: function() {
    for ( i = 0; i < parent.frames.length; ++i )
      if ( parent.frames[i].FCK )
        parent.frames[i].FCK.UpdateLinkedField();
  }
}

Then add :onclick => "FCKFixer.fixIt();" as an argument to your submit tag. So, now your entire form should look something like...

<% remote_form_for :comment, @comment, :url => post_comments_path(@post) do |f| %>
    <%= f.date_select :birthday %>
    <%= f.select :flag, [['You Rock',:rocks],["You're Great",:great],['Can I Have Your Babies?',:have_babies_request]] %>
    <%= fckeditor_textarea :comment, :body %>
    <%= submit_tag 'Submit', :onclick => "FCKFixer.fixIt();" %>
<% end %>

That's it? Yes! Really? Yes! Have a nice day and see you next time.

Comments: 2

A project at the day job has me implementing some in pace editing. A quick search of the web found this page with a nice helper method that does all the hard work for me. Problem was, we're using RESTful routes and I was getting errors. Looking through the comments on the above linked blog post it was obvious I wasn't the only one having problems. Some more research and I think I've got it solved. Two options need to be added to the :ajax section of the options.

:ajax => {
  :ajaxOptions => "{ method: 'put' }",
  :paramName => "'my_model[my_field]'"
}

REST expects updates to be sent as a PUT, not a POST, which is what the browser wants to do by default, hence the necessity of the first option.

Next, paramName seems to be an undocumented option that I found only after digging through the Prototype source code. That changes the name of the text field in the form, so that it plays nicely with Rails apps. Obviousl,y you'll need to change 'my_model[my_field]' to the appropriate model and field names. Notice the nested double and single quotes... these are IMPORTANT!

With those two options added to the rest, it seems to work like a charm.

Comments: 2