Created
November 12, 2008 18:17
-
-
Save teamon/24222 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
%w(text_field password_field hidden_field file_field | |
text_area select check_box radio_button radio_group).each do |kind| | |
self.class_eval <<-RUBY, __FILE__, __LINE__ + 1 | |
def labeled_#{kind}(*args) | |
options = args.last.is_a?(Hash) ? args.pop : {} | |
options[:label] = args.first.to_s.gsub('_', ' ').capitalize.t + ":" unless options[:label] | |
args.push(options) | |
#{kind}(*args) | |
end | |
RUBY | |
end | |
def default_error_messages_for(obj, opts = {}) | |
error_messages_for obj, :build_li => "<li>%s</li>", :header => "<h3>#{"Oops! There are some errors:".t}</h3>" | |
end |
This file contains hidden or 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
- box "Edit translation:".t, :type => :wide do | |
= form_for @translation, :action => url(:translation, @translation) do | |
= fieldset do | |
%p | |
= labeled_text_field :id, :disabled => true | |
= labeled_text_field :value | |
= hidden_field :language, :value => @translation.language | |
%p.actions | |
= submit 'Save'.t | |
= link_to 'Back'.t, url(:translations, :language => @translation.language) | |
- if @translation.related.size > 0 | |
%h3= "Related translations".t | |
- @translation.related.each do |t| | |
= fields_for(t) do | |
= fieldset do | |
%p | |
= text_field :name => "translation[related][#{t.hash}][id]", :value => t.id, :disabled => true, :label => "#{"Id".t}:" | |
= text_field :name => "translation[related][#{t.hash}][value]", :value => t.value, :label => "#{"Value".t}:" | |
%p.actions | |
= submit 'Save'.t | |
= link_to 'Back'.t, url(:translations, :language => @translation.language) |
This file contains hidden or 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
- box "Edit article:".t do | |
= form_for @article, :action => url(:article, @article) do | |
= default_error_messages_for @article | |
= fieldset do | |
%p= labeled_text_field :title | |
%p= labeled_text_area :content | |
%p.actions | |
= submit 'Save'.t | |
= link_to 'Back'.t, url(:articles) |
This file contains hidden or 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
= default_error_messages_for @product | |
= fieldset :legend => 'Category'.t do | |
%p | |
%span#product_categories | |
%p | |
= text_field :category_id | |
%span#product_category_id_label | |
= fieldset do | |
%p | |
= label "Product type:".t | |
= radio_group :type, Product.types | |
%p= labeled_text_field :name | |
%p= labeled_text_area :description | |
= fieldset :legend => "Images:" do | |
- @product.max_attachments_size.times do |i| | |
%p | |
- if a = @product.attachments[i] | |
= file_field :name => "product[attachments][#{a.id}][data]", :label => a.filename | |
= check_box :name => "product[attachments][#{a.id}][delete]", :label => "Delete?".t | |
- else | |
= file_field :name => "product[attachments][new][]", :label => "Image %d:".t(i+1) | |
= fieldset :legend => "Options:".t do | |
- Option.all.each do |option| | |
%p | |
= label option.name | |
- if valid = @product.active_option?(option) | |
%span.option_info | |
= "Option valid until:".t | |
= valid.strftime("%Y-%m-%d %H:%M") | |
- else | |
= select_for_option(option) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment