automate linking to Twitter users
def link_twitter_user(txt) if match = txt.match(/.*?(@)((?:[a-z][a-z]+))(:|\s)/i) user = match[2] txt.gsub!(user, '<a href="http://twitter.com/' + user + '">' + user + '</a>') end txt end
11345 users tagging and storing useful source code snippets
Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world
def link_twitter_user(txt) if match = txt.match(/.*?(@)((?:[a-z][a-z]+))(:|\s)/i) user = match[2] txt.gsub!(user, '<a href="http://twitter.com/' + user + '">' + user + '</a>') end txt end
<% if @client.service_events.empty? -%> | <%= link_to "delete", :controller => "admin", :action => "destroy_client", :id => @client %><% end -%>
# throw this in one of your controller helpers. # it works just like a combination of link_to_unless_current and link_to_remote def link_to_remote_unless_current(name, options = {}, html_options = {}, *parameters_for_method_reference, &block) if current_page?(options[:url]) if block_given? block.arity <= 1 ? yield(name) : yield(name, remote_function(options), html_options, *parameters_for_method_reference) else name end else link_to_function(name, remote_function(options), html_options) end end
def javascript_link_to(name, javascript, html_options = nil, *parameters_for_method_reference) options = [ :action => @params["action"] ] html_options = { :onclick => javascript+"return false" } link_to(name, options, html_options, *parameters_for_method_reference) end
// method 1 <a href='#' onclick='alert("hello"); return false'>hello</a> // method 2 <a href='javascript:alert("hello")'>hello</a>
<a href="" hreflang="fr">a link to a french page</a>
a:after { content: attr(hreflang); color: #999; margin-left: 0.2em; }
<a href="#" onClick="<%= remote_function(:update => 'fashion1', :url => { :action => :get_fashion_for_color, :color_name => color_name, :number => 1 })%>;
<%= remote_function(:update => 'fashion2', :url => { :action => :get_fashion_for_color, :color_name => color_name, :number => 2 })%>;
<%= remote_function(:update => 'fashion3', :url => { :action => :get_fashion_for_color, :color_name => color_name, :number => 3 })%>;
return false;">