js.erb
$('#search_div').html('<%=j render :partial=> 'find_book',locals: { book: @results }, :formats => :html %>')
html.erb
<% @book=book %>
<%= @book.inspect %>
<% @book.id %>
当我进行检查时,它可以找到并显示给我
[#<Book id: 55, name: "consequatur laborum quidem excepturi", isbn: 9782943127358, price: 4023, comment: nil, created_at: "2013-09-01 02:59:29", updated_at: "2013-09-01 02:59:29", author: nil, sale_type: nil, publisher: nil, sn: nil, category: nil>] [#<Book id: 55, name: "consequatur laborum quidem excepturi", isbn: 9782943127358, price: 4023, comment: nil, created_at: "2013-09-01 02:59:29", updated_at: "2013-09-01 02:59:29", author: nil, sale_type: nil, publisher: nil, sn: nil, category: nil>]
但是当我尝试使用 @book.id
它给了我。
ActionView::Template::Error (undefined method `id' for #<Array:0x007faef875b260>):
1: <% @book=book %>
2: <%= @book.inspect %>
3: <% @book.id %>