<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DZone Snippets: stylesheets code</title>
    <link>http://snippets.dzone.com/posts</link>
    <pubDate>Sat, 26 Jul 2008 23:39:08 GMT</pubDate>
    <description>DZone Snippets: stylesheets code</description>
    <item>
      <title>Use background color to show error fields instead of wrapping them in a div</title>
      <link>http://snippets.dzone.com/posts/show/1912</link>
      <description>Using the default rails field_error_proc may lead to some layout headaches--your form looks perfect until, uh-oh, someone entered an invalid email address and Rails adds a fieldWithError-styled div that wraps around the problem field.&lt;br /&gt;&lt;br /&gt;While this works in many cases, some pixel-perfect layouts may not be able to tolerate the 2-pixel padding around the text_field caused by the red border.  An alternative is to change the background color of the offending field.&lt;br /&gt;&lt;br /&gt;Include the following code in environment.rb (or use a "require" like I do):&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;ActionView::Base.field_error_proc = Proc.new do |html_tag, instance|&lt;br /&gt;  error_style = "background-color: #ffff80"&lt;br /&gt;  if html_tag =~ /&lt;(input|textarea|select)[^&gt;]+style=/&lt;br /&gt;    style_attribute = html_tag =~ /style=['"]/&lt;br /&gt;    html_tag.insert(style_attribute + 7, "#{error_style}; ")&lt;br /&gt;  elsif html_tag =~ /&lt;(input|textarea|select)/&lt;br /&gt;    first_whitespace = html_tag =~ /\s/&lt;br /&gt;    html_tag[first_whitespace] = " style='#{error_style}' "&lt;br /&gt;  end&lt;br /&gt;  html_tag&lt;br /&gt;end&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;See my blog.inquirylabs.com for more Rails stuff.</description>
      <pubDate>Thu, 13 Apr 2006 22:21:47 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/1912</guid>
      <author>canadaduane (Duane Johnson)</author>
    </item>
    <item>
      <title>Autoinclude CSS Files by Controller/Action Name</title>
      <link>http://snippets.dzone.com/posts/show/509</link>
      <description>&lt;code&gt;&lt;br /&gt;def stylesheet_auto_link_tags&lt;br /&gt;  stylesheets_path = "#{RAILS_ROOT}/public/stylesheets/"&lt;br /&gt; &lt;br /&gt;  candidates = [ "#{controller.controller_name}", &lt;br /&gt;                 "#{controller.controller_name}_#{controller.action_name}" ]&lt;br /&gt; &lt;br /&gt;  candidates.inject("") do |buf, css| &lt;br /&gt;    buf &lt;&lt; stylesheet_link_tag(css) if FileTest.exist?("#{stylesheets_path}/#{css}.css")&lt;br /&gt;    buf&lt;br /&gt;  end&lt;br /&gt;end&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;Compliments of Dema&lt;br /&gt;&lt;br /&gt;Note: Anyone interested in this might also be interested in the bundled_resource plugin (google for it).</description>
      <pubDate>Tue, 26 Jul 2005 06:16:30 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/509</guid>
      <author>canadaduane (Duane Johnson)</author>
    </item>
  </channel>
</rss>
