Skip to content

Instantly share code, notes, and snippets.

@simonrobson
Created July 29, 2009 13:31
Show Gist options
  • Save simonrobson/158168 to your computer and use it in GitHub Desktop.
Save simonrobson/158168 to your computer and use it in GitHub Desktop.
<!-- Note: this depends on this patch being applied:
http://github.com/simonrobson/spree/commit/5d94572bf5ba8fe8198a21dc1253845603fb3c9d -->
<p>
<% attribute = field[:name].gsub(" ", "_").downcase %>
<%= f.label attribute, field[:name] %>
<% if f.object && f.object.column_for_attribute(attribute).type == :boolean %>
<%= f.check_box attribute %>
<% else %>
<br />
<% val = f.object.send(attribute.to_sym) rescue nil
formatted_value = (val.nil? || !field.key?(:format)) ? val : val % field[:format] %>
<%= f.text_field attribute, :value => formatted_value %>
<% end %>
<%= f.error_message_on attribute %>
</p>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment