request variables
Example: HTTP_USER_AGENT
request.env["HTTP_USER_AGENT"]
returns the browser's user_agent setting
2807 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 (or not, you can keep them private!)
request.env["HTTP_USER_AGENT"]
module ActiveRecord class Errors begin @@default_error_messages = { :empty => "dient verplicht ingevuld te worden", :blank => "dient verplicht ingevuld te worden", } end end end
def toggle_showall render(:update) do |page| page[:fb_content].replace_html "just text? ripoff!" page[:flash_box].visual_effect :blind_down, :duration => 0.25 end end
page[:fb_content]
page[:fb_content].replace_html "just text? ripoff!"
page[:fb_content].replace_html :partial => "shared/some_partial"
page[:flash_box].visual_effect :blind_down, :duration => 0.25
include ActionView::Helpers::DateHelper
def original_control_handler [misc methods and other things] [done normally in this controller] render :update do |page| page.replace_html 'calling_element_id', :partial => 'updated_template' page.helper 'helper_id', :helper_options => 'go here' end end
... page.replace_html 'element_to_update', "this string goes in element"
page.replace 'element2_to_update', (link_to_remote "link_text", {:url => dest, :method => :get, :id => 'element2_to_update')
?chapter=9&sort_by=created_at&sort_dir=desc
:with => "'chapter='+ encodeURIComponent(value)+'&sort_by=#{@sort_by}&sort_dir=#{@sort_dir}&='", :update => 'list_items'
<%= javascript_include_tag "prototype" %>
<%= link_to_function @toggle_text, remote_function(:url => watch_lists_path, :method => :post, :with => "Form.serialize('watch_form')", :update => 'follow_anchor'), :id => 'follow_anchor' %>
def create @watch_list = WatchList.new(params[:watch_list]) if @watch_list.toggle render(:text => @watch_list.toggle_text) else render(:text => 'We couldn''t add this book to your Watch List. Please contact us for help.') end end
logger = Logger.new(STDOUT) logger.debug ("title: #{@attr.get('title')}") logger.debug("small_image: #{@images.search_and_convert('smallimage')}")
debug(@instance_var.pretty_inspect)
mysql_config --socket sudo ln -s /var/run/mysqld/mysqld.sock /tmp/mysql.sock
$HTTP["host"] =~ "(www\.)?(hatepad|sexymsg)\.(com|net)" { server.document-root = base + "/domains/sexymsg.com/web/public/" server.error-handler-404 = "/dispatch.fcgi" fastcgi.server = ( ".fcgi" => ( "localhost" => ( "socket" => base + "/var/run/sexymsg-0.socket" ) ) ) }
kill -9 <lighttpd PID> . ~/etc/rc.d/lighttpd.sh start
def tag_unless_empty(html_tag, options = {}, &block) html_options = options.stringify_keys if block_given? content = capture(&block) unless content.strip.empty? concat(tag(html_tag, html_options, true), block.binding) concat(content, block.binding) concat("#{html_tag}>", block.binding) end end end
<% tag_unless_empty :div, :class => "css_class" do %> <%# Nothing actually rendered here %> <%# or here %> <% end %>
<% tag_unless_empty :div, :class => "css_class" do %> <%= 'Something rendered here' %> <% end %>
<div class="css_class">Something rendered herediv>
ENV[‘DB’] = ‘mysql’to /config/environment.rb
rescue Technoweenie::AttachmentFu::Backends::S3Backend::RequiredLibraryNotFoundErrorto /vendor/plugins/attachment_fu/test/fixtures
def is_admin? #TODO: make into an accessor? return false unless self.tiers tier_names = self.tiers.collect {|t| t.name} return tier_names.include? "admin" end
class LoadTiersUsers < ActiveRecord::Migration extend MigrationHelpers class Tier < ActiveRecord::Base; has_and_belongs_to_many :users end class User < ActiveRecord::Base; has_and_belongs_to_many :tiers end class TiersUsers < ActiveRecord::Base; end def self.up p "*** Loading user, tier data..."
<% unless flash[:notice].nil? %>><%= flash[:notice] %><% end %> <% unless flash[:error].nil? %>="notice"><%= flash[:error] %><% end %> ... etc.
<% flash.each do |key, msg| %> <%= content_tag :div, msg, :id => key %> <% end %>
map.tag 'tags/:tag', :controller => 'tags', :action => 'show', :conditions => {:method => :get}
render :template => ''
def show [boring action logic] render :template => 'lists/index' end
layout ""
<%= stylesheet_link_tag 'scaffold', 'tag_cloud' %>
/* tag_cloud styles*/ .nube1 {font-size: 1.0em;} .nube2 {font-size: 1.2em;} .nube3 {font-size: 1.4em;} .nube4 {font-size: 1.6em;} .nube5 {font-size: 1.8em;} .nube6 {font-size: 2.0em;}
TAG CLOUD<br/> <%= render(:partial => "shared/article_tag_cloud", :locals => {:tags => @tags}) %>
<% # For our purposes, have this filter the list of articles to those with the chosen tag tag_cloud true, tags, %w(nube1 nube2 nube3 nube4 nube5) do |name, css_class| %> <%= link_to name, tag_path(name), class => css_class # links to Tag resource, with tag name as 'id' %> <% end %>
def tag_cloud(active, tags, classes) if !active then return end max, min = 0, 0 unless tags.empty? tags.sort! {|x,y| y.count <=> x.count} max = tags.first.count min = tags.last.count end divisor = ((max - min) / classes.size) + 1 tags.each { |t| yield t.name, classes[(t.count.to_i - min) / divisor] } end