ninajansen.dk

ninajansen.dk header image 1

In place editing in rails

maj 13th, 2008 · Comments

So basically, the official plugin is old and cant really deal with restful routing. For some reason, when I used the url_for method in my views, the in place editor javascript function couldn’t interpret the (restful) route properly and sent a post request to ‘/controller/1/edit’ to an action named “1″ with an id set to “edit”, which obviously didn’t do anything useful. So instead I called the in place editor script in the following manner (I’m using haml btw.):


%span{:id => "name", :class => "in_place_editor_field"}= @user.name
= in_place_editor "name", {:url => '/user/edit/' + @user.id.to_s, :rows => 1, :size => 32 }

So basically I hard coded the route so it would fall back on standard routing. Yes I know that:

  • This is ugly as sin
  • I’m supposed to do a PUT request to a function named update, not a post request to a function named edit.

But it solved the problem.

Popularity: 94% [?]

Tags: REST · Ruby on Rails · tips