Permalink
Browse files

Use show_for gem for shows

  • Loading branch information...
1 parent 0f3d68d commit cfb1783df2247f64673a2b0939db3cf71ef1382d @denispeplin committed Jun 2, 2012
View
@@ -9,6 +9,8 @@ gem 'sqlite3'
gem 'simple_form'
+gem 'show_for'
+
# Gems used only for assets and not required
# in production environments by default.
group :assets do
View
@@ -107,6 +107,9 @@ GEM
railties (~> 3.2.0)
sass (>= 3.1.10)
tilt (~> 1.3)
+ show_for (0.2.5)
+ actionpack (~> 3.0)
+ activemodel (~> 3.0)
simple_form (2.0.1)
actionpack (~> 3.0)
activemodel (~> 3.0)
@@ -140,6 +143,7 @@ DEPENDENCIES
rails (= 3.2.1)
rspec-rails
sass-rails (~> 3.2.3)
+ show_for
simple_form
sqlite3
twitter-bootstrap-rails
@@ -1,9 +1,8 @@
<h1>Brand</h1>
-<p>
- <b>Name</b><br>
- <%= @brand.name %>
-</p>
+<%= show_for @brand do |b| %>
+ <%= b.attribute :name %>
+<% end %>
<div class="form-actions">
<%= link_to 'Back', brands_path, :class => 'btn' %>
@@ -1,9 +1,8 @@
<h1>Category</h1>
-<p>
- <b>Name</b><br>
- <%= @category.name %>
-</p>
+<%= show_for @category do |c| %>
+ <%= c.attribute :name %>
+<% end %>
<div class="form-actions">
<%= link_to 'Back', categories_path, :class => 'btn' %>
@@ -1,24 +1,11 @@
<h1>Product</h1>
-<p>
- <b>Name</b><br>
- <%= @product.name %>
-</p>
-
-<p>
- <b>Price</b><br>
- <%= @product.price %>
-</p>
-
-<p>
- <b>Category</b><br>
- <%= @product.category_name %>
-</p>
-
-<p>
- <b>Brand</b><br>
- <%= @product.brand_name %>
-</p>
+<%= show_for @product do |p| %>
+ <%= p.attribute :name %>
+ <%= p.attribute :price %>
+ <%= p.attribute :category_name %>
+ <%= p.attribute :brand_name %>
+<% end %>
<div class="form-actions">
<%= link_to 'Back', products_path, :class => 'btn' %>
@@ -0,0 +1,37 @@
+# Use this setup block to configure all options available in ShowFor.
+ShowFor.setup do |config|
+ # The tag which wraps show_for calls.
+ # config.show_for_tag = :div
+
+ # The tag which wraps each attribute/association call. Default is :p.
+ # config.wrapper_tag = :dl
+
+ # The tag used to wrap each label. Default is :strong.
+ # config.label_tag = :dt
+
+ # The tag used to wrap each content (value). Default is nil.
+ # config.content_tag = :dd
+
+ # The DOM class set for blank content tags. Default is "blank".
+ # config.blank_content_class = 'no_content'
+
+ # The separator between label and content. Default is "<br />".
+ config.separator = ' '
+
+ # The tag used to wrap collections. Default is :ul.
+ # config.collection_tag = :ul
+
+ # The default iterator to be used when invoking a collection/association.
+ # config.default_collection_proc = lambda { |value| "<li>#{ERB::Util.h(value)}</li>".html_safe }
+
+ # The default format to be used in I18n when localizing a Date/Time.
+ # config.i18n_format = :default
+
+ # Whenever a association is given, the first method in association_methods
+ # in which the association responds to is used to retrieve the association labels.
+ # config.association_methods = [ :name, :title, :to_s ]
+
+ # If you want to wrap the text inside a label (e.g. to append a semicolon),
+ # specify label_proc - it will be automatically called, passing in the label text.
+ # config.label_proc = lambda { |l| l + ":" }
+end
@@ -0,0 +1,5 @@
+en:
+ show_for:
+ blank: "Not specified"
+ "yes": "Yes"
+ "no": "No"
@@ -0,0 +1,8 @@
+<%%= show_for @<%= singular_name %> do |s| %>
+<% attributes.each do |attribute| -%>
+ <%%= s.<%= attribute.reference? ? :association : :attribute %> :<%= attribute.name %> %>
+<% end -%>
+<%% end %>
+
+<%%= link_to 'Edit', edit_<%= singular_name %>_path(@<%= singular_name %>) %> |
+<%%= link_to 'Back', <%= plural_name %>_path %>

0 comments on commit cfb1783

Please sign in to comment.