Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@kofno
Created May 22, 2015 03:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kofno/2762bcc615ce7440b7f0 to your computer and use it in GitHub Desktop.
Save kofno/2762bcc615ce7440b7f0 to your computer and use it in GitHub Desktop.
Simple js partial example.
$('#the-modal').html('<%=j render('form') %>')
$('#the-modal').modal('show')
# This doesn't work
Element.expose :modal
the_modal = Element['#the-modal']
the_modal.html = j render('form') # this doesn't work... maybe it needs to be processed by erb too?
the_modal.modal 'show'
@elia
Copy link

elia commented Jun 12, 2015

@kofno if you assign the rendered template to an instance variable you should be able to get it in the template, eg.:

# controller

def new
  @form_html = render(partial: 'form')
end
# template
Element.expose :modal

the_modal = Element['#the-modal']
the_modal.html = @form_html
the_modal.modal :show

You can't mix server side code like render into an opal template because it's executed in the client. In fact you can only pass json compatible values to instance variables (string, number etc. are ok, an object is not).

@kofno
Copy link
Author

kofno commented Jun 12, 2015

Thanks. I'll take a look at that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment