开发者

Rails In Place Editing

开发者 https://www.devze.com 2023-01-22 21:30 出处:网络
I\'m using rails 3 and am trying to use the in_place_editing plugin: http://github.com/wanglian/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
  <%=开发者_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 %>
0

精彩评论

暂无评论...
验证码 换一张
取 消