views:

183

answers:

1

I am using the "in_place_editing" plugin for rails to render a form with in-place edits. Thing work fine as long as the default template is chosen by rails (no 'render' method is invoked inside the controller), but they break down when I try to render a partial using "render :partial => 'partial_name'" call. Is this a known issue (in_place_edit does not work with partials?) or am I missing something? I am getting the following error while rendering the partial:

Called id for nil, which would mistakenly be 4 -- if you really wanted the id of nil, use object_id
.../vendor/plugins/in_place_editing/lib/in_place_macros_helper.rb:74:in `in_place_editor_field'
+1  A: 

You don't provide anywhere near enough information in your question, giving only two lines of the backtrace and no fragments of the view which does work, or the partial which does not. This means that any attempts to answer you must be based largely on guesswork. That said, the in-place editor helper is just a helper method like any other, nothing special. You can call it from just about any view component. It is highly likely that the way in which that view is included by the controller, or indeed a parent view, is not the reason it is failing.

The helper method is complaining about a nil value. This means that most likely, your partial is invoking in_place_editor_field and passing it values which are not defined in the partial. Check to make sure it isn't using local variables which are not defined, compared to those used in the view where your in_place_editor_field call works; check to make sure that it isn't asking for different instance variables too. In all probability you'll find the views which work are using one variable name while the partial you've tried to render is using another.

The render :partial => ... mechanism supports different ways of explicitly passing in values to the partial; you may choose to use these to clarify your code. See the :locals and :object options for the "Rendering partials" section of the render documentation in the Rails API at:

Andrew Hodgkinson
My apologies for the lack of information. But I was trying to use the in_place_editing plugin after just reading the README which basically has 2 lines (one for the change in the controller and the other in the view). Which I realize now is a big mistake! I found out that the plugin needs an instance variable with the exact name as the model defined for it to work. I wish the README was a little more explicit (maybe a third line on the instance variable definition). Thanks for your answer, you caught the error perfectly with just the information I gave :)
Raghu
Yep. Sadly, Rails is very patchy for documentation. The core is quite well covered now - Rails Guides was a big step forward - but the same can't be said for lots of related plugins and gems.Your particular problem is down to one of several API oversights in the original in-place editor plugin. I wrote a replacement to get around a huge XSS vulnerability which it used to have and it still has a few features which the core plugin lacks. Shameless plug:http://rubyforge.org/projects/safeinplaceedit/
Andrew Hodgkinson