Created
August 22, 2011 02:07
-
-
Save haxney/1161502 to your computer and use it in GitHub Desktop.
Genericizing Rails views
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
= semantic_form_for entry do |f| | |
= f.inputs | |
= f.buttons |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
attributes(:id, :name, :email, :phone, :picture) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
%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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
collection @entries | |
extends "#{entry_views_folder_path}/base" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def entry_class | |
User | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment