Creating and Integrating Bookmarklets with Rails

Code Samples From Video

app/views/bookmarks/index.html.erb

<p>
  <a href="javascript:var d=document,w=window,e=w.getSelection,k=d.getSelection,x=d.selection,s=(e?e():(k)?k():(x?x.createRange().text:0)),f= 'http://<%= request.host_with_port %>/bookmarks/new',l=d.location,e=encodeURIComponent,p='?v=1&u='+e(l.href)%20+'&t='+e(d.title.replace(/^\s*|\s*$/g,''))%20+'&s='+e(s),u=f+p;location.href=u;">
    Bookmarklet
  </a>
</p>

app/controllers/bookmarks_controller.rb

@bookmark.title   = params[:t]
@bookmark.content = params[:s]
@bookmark.url     = params[:u]

Rails Tips Articles

Rails Quick Tips