Search code examples
ruby-on-railsruby-on-rails-3ruby-on-rails-plugins

Rails In Place Editing


I'm using rails 3 and am trying to use the in_place_editing plugin:

http://github.com/wanglian/in_place_editing

 # Controller
  class BlogController < ApplicationController
    in_place_edit_for :post, :title
  end

  # View
  <%= in_place_editor_field :post, 'title' %>

However I'm getting the error: id for nil, which would mistakenly be 4 -- if you really wanted the id of nil, use object_id

I'm calling the plugin in my photo_album controller, which has a title attribute...

class PhotoAlbumsController < ApplicationController

  in_place_edit_for :photo_album, :title

The in the Index View, I'm doing the following:

<% @photoalbums.each do |photoalbum| %>
     <%= in_place_editor_field :photoalbum, 'title' %>
<% end %>

Does anyone understand this or have experience with this plugin?

Thanks


Solution

  • The error is because, its trying to update the title of a nil object. You should use this instead

    <% @photoalbums.each do |photoalbum| %>
         <%= in_place_editor_field photoalbum, 'title' %>
    <% end %>
    

    if you see the code of the plugin the definition of the method is

    def in_place_editor_field(object, method, tag_options = {}, in_place_editor_options = {})