Skip to content

Instantly share code, notes, and snippets.

@recursive
Created February 22, 2010 02:04
Show Gist options
  • Select an option

  • Save recursive/310704 to your computer and use it in GitHub Desktop.

Select an option

Save recursive/310704 to your computer and use it in GitHub Desktop.
def html_safe_ajax_partial(name, partial, div)
link_to_remote name, :url => new_session_url(:partial => partial, :format => 'js'), :update => div, :method => :get, :html => { :href => new_session_url(:partial => partial) }
end
#html_safe_ajax_partial('Hello', 'hi', 'coolstuff')
#The above properly generates http://domain/session/new?partial=hi in the coolstuff div with text 'Hello'
#<a onclick="new Ajax.Updater('page_contents', 'http://localhost:3001/session/new.js?partial=hi', {asynchronous:true, evalScripts:true, method:'get', parameters:'authenticity_token=' + encodeURIComponent('U44dXFOJa2g4cpjYTL+SwSySN3lh0jo9dD8joocNEgo=')}); return false;" href="http://localhost:3001/session/new?partial=about">Hello</a>
#I want one to generate:
#<a onclick="new Ajax.Updater('page_contents', 'http://localhost:3001/session/new.js?partial=hi', {asynchronous:true, evalScripts:true, method:'get', parameters:'authenticity_token=' + encodeURIComponent('U44dXFOJa2g4cpjYTL+SwSySN3lh0jo9dD8joocNEgo=')}); return false;" href="http://localhost:3001/session/new?partial=about"><span><span>Hello</span></span></a>
#Notice the spans -- I have to do this as the css guy did it this way :(
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment