Skip to content

Instantly share code, notes, and snippets.

@ntreadway
Created April 18, 2012 17:27
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save ntreadway/2415268 to your computer and use it in GitHub Desktop.
Save ntreadway/2415268 to your computer and use it in GitHub Desktop.
Simple page inject for JQuery Mobile and Rails Partials
# Used to dynamically add a rails page view when using Jquery Mobile
# Author Nick Treadway @nicktea
@insert_page = (id, content) ->
page = $("<article id="+id+" data-role='page' data-url="+id+" data-add-back-btn='true'>" + content + "</article>")
page.appendTo('body')
$('a' + '#' + id).click ->
$.mobile.changePage(page, {transition: "slide"})
# Use (your-view.haml)
:javascript
var content = "#{escape_javascript(render :partial => 'content')}"
insert_page("your-id", content);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment