Monday, June 22, 2009

Weird path issues from upgrading rails

This issue came up when a request to the update action was giving this error:
ActionController::MethodNotAllowed? (Only get and post requests are allowed.)

Okay. At first I thought it was an issue with the form itself or the params being passed, but then I looked at the route method in the view and saw this:
:url => members_path(current_member)

Looks okay, but it's not. At some point between Rails 2.1.0 and 2.3.2, pluralized calls changed their meaning. To debug this, I went to irb. "IRB?!?" you say? Yep. You can get to these methods by using the "app" variable.

> script/console
>> app.members_path(Member.last)
=> "/members.%23%3Cmember:0x3d8838c%3E"

There's a dot in the path? That's weird. What if I try:

>> app.member_path(Member.last)
=> "/members/721714"

Sweet, back to a normal slash, and it's smart enough to grab the id, instead of the object.

For more about tricks with the irb, see the irb mix tape post from err the blog.

No comments:

Post a Comment