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
<%=开发者_StackOverflow中文版 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
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 = {})
In case you need to use in_place_editor_field
in a loop, do something like this:
Class Item < AR::Base
#attributes like name, price
end
<% for some_item in @items %>
<% @item = some_item %>
<%= in_place_editor_field :item, :price %>
<% end %>
精彩评论