Closed shmeltex closed 11 years ago
@shmeltex child
should be use to render data associated with the parent model (i.e. it will try to call a method or a relation in your model). In your example, there is no model since you used object false
.
If you want to render the @notes
instance variable you should use
child(:@notes => :data, :partial => 'notes/_single')
Thanks for the PR anyway !
@ccocchi I used your suggestion and it still fails with
ActionView::Template::Error: undefined method `notes` for nil:NilClass
My template looks like this now:
object false
child({:notes => :data}, :partial => "notes/_single")
node(:success) { true }
Just to put it into the context, I'm trying to get to the following output:
{
"data": [
{
"id": 1,
"note": "Note 1"
},
{
"id": 2,
"note": "Note 2"
}
],
"success": true
}
@shmeltex You missed the @
before notes
to reference an instance variable => :@notes ;)
@ccocchi Actually, I didn't. In the controller I'm using decent_exposure gem to expose data to views as methods instead of instance variables.
Here is my controller:
class NotesController < ApplicationController
respond_to :json
expose(:notes) { Note.all }
def index
respond_with(notes)
end
end
Hmm. I'll check how _decentexposure passed variables to the view. Currently, RablRails copies instances variables from @assigns
variables. Maybe _decentexposture does not use this ivar.
It should be fixed with 8376c0d974cb21bd608bebc0a9dde52aae7aa5c2. @shmeltex Can you confirm please ?
Confirmed, works with both
object false
child({:notes => :data}, :partial => "notes/_single")
node(:success) { true }
and
object false
child :notes => :data do
extends "notes/_single"
end
node(:success) { true }
Thank you for your work on the gem!
Great ! I've just released a new version with this fix. Thank you for the report !
Following template fails to render:
It fails with error