Skip to content

Instantly share code, notes, and snippets.

@haxney
Created August 22, 2011 02:07
Show Gist options
  • Save haxney/1161502 to your computer and use it in GitHub Desktop.
Save haxney/1161502 to your computer and use it in GitHub Desktop.
Genericizing Rails views
= semantic_form_for entry do |f|
= f.inputs
= f.buttons
attributes(:id, :name, :email, :phone, :picture)
%h1= t('.title')
%p= link_to t(".new_#{entry_class.name.underscore}"), polymorphic_path(entry_class, :action => :new)
%table
%thead
%tr
%th ID
-# This is horrible, but there doesn't seem to be any other way to get
model attributes without creating an actual object instance.
- for header in entry_class.new.attribute_names
%th= entry_class.human_attribute_name header
%th{:colspan => 3}= t 'actions'
%tbody
- for entry in @entries
%tr{ :class => cycle(:odd, :even) }
%td= entry.id
- for key, val in entry.attributes.except('id')
%td= val
%td.action= link_to t('show'), entry
%td.action= link_to t('edit'), polymorphic_path(entry, :action => :edit)
%td.action= link_to t('destroy'), entry, :confirm => t('are_you_sure'), :method => :delete
collection @entries
extends "#{entry_views_folder_path}/base"
def entry_class
User
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment