From ca50f7df31fee3e800d1f4c61d36469d5677da30 Mon Sep 17 00:00:00 2001 From: AntonioTerceiro Date: Wed, 12 Sep 2007 20:47:32 +0000 Subject: [PATCH] ActionItem65: DRY approach to translation of forms --- app/controllers/account_controller.rb | 2 +- app/helpers/application_helper.rb | 21 ++++++++++++++++++++- app/models/person_info.rb | 6 +++--- app/models/user.rb | 3 +++ app/views/account/login.rhtml | 2 +- app/views/account/signup.rhtml | 24 +++++++++--------------- 6 files changed, 37 insertions(+), 21 deletions(-) diff --git a/app/controllers/account_controller.rb b/app/controllers/account_controller.rb index 11bcbc2..f648a33 100644 --- a/app/controllers/account_controller.rb +++ b/app/controllers/account_controller.rb @@ -27,7 +27,7 @@ class AccountController < ApplicationController def signup begin @terms_of_use = virtual_community.terms_of_use - terms_accepted = params[:user] ? params[:user].delete(:terms_accepted) : false + terms_accepted = params[:terms_accepted] @user = User.new(params[:user]) return unless request.post? if @terms_of_use and !terms_accepted diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index dab64ba..6a1fdfa 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -153,7 +153,7 @@ module ApplicationHelper # returns the current profile beign viewed. # # Make sure that you use this helper method only in contexts where there - # should be a currnt profile (i.e. while viewing some profile's pages, or the + # should be a current profile (i.e. while viewing some profile's pages, or the # profile info, etc), because if there is no profile an exception is thrown. def profile @profile || raise("There is no current profile") @@ -167,4 +167,23 @@ module ApplicationHelper content_tag('div', content_tag('div', content_tag('label', label)) + html_for_field, :class => 'formfield') end + def labelled_form_for(name, object = nil, options = {}, &proc) + object ||= instance_variable_get("@#{name}") + form_for(name, object, { :builder => NoosferoFormBuilder }.merge(options), &proc) + end + + class NoosferoFormBuilder < ActionView::Helpers::FormBuilder + include GetText + + (field_helpers - %w(hidden_field)).each do |selector| + src = <<-END_SRC + def #{selector}(field, *args, &proc) + column = object.class.columns_hash[field.to_s] + "
" + "
" + super + "
" + end + END_SRC + class_eval src, __FILE__, __LINE__ + end + end + end diff --git a/app/models/person_info.rb b/app/models/person_info.rb index fa3bcad..0b24dd3 100644 --- a/app/models/person_info.rb +++ b/app/models/person_info.rb @@ -6,9 +6,9 @@ class PersonInfo < ActiveRecord::Base def summary [ - [ _('Name'), self.name ], - [ _('Address'), self.address ], - [ _('Contact Information'), self.contact_information ], + [ PersonInfo.columns_hash['name'].human_name, self.name ], + [ PersonInfo.columns_hash['address'].hunam_name, self.address ], + [ PersonInfo.columns_hash['contact_information'], self.contact_information ], ] end diff --git a/app/models/user.rb b/app/models/user.rb index 71da3e8..6de91e0 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -4,6 +4,9 @@ require 'digest/sha1' # Rails generator. class User < ActiveRecord::Base + N_('User|Password') + N_('User|Password confirmation') + after_create do |user| Person.create!(:identifier => user.login, :name => user.login, :user_id => user.id) end diff --git a/app/views/account/login.rhtml b/app/views/account/login.rhtml index 11b850e..8a6e8a0 100644 --- a/app/views/account/login.rhtml +++ b/app/views/account/login.rhtml @@ -1,7 +1,7 @@

<%= _('Login') %>

<% form_tag do -%> -


+


<%= text_field_tag 'login' %>


diff --git a/app/views/account/signup.rhtml b/app/views/account/signup.rhtml index 5a07b58..8e48b3f 100644 --- a/app/views/account/signup.rhtml +++ b/app/views/account/signup.rhtml @@ -1,23 +1,17 @@

<%= _('Register') %>

<%= error_messages_for :user %> -<% form_for :user do |f| -%> -


-<%= f.text_field :login %>

- -


-<%= f.text_field :email %>

- -


-<%= f.password_field :password %>

- -


-<%= f.password_field :password_confirmation %>

+<% labelled_form_for :user, @user do |f| -%> + +<%= f.text_field :login %> +<%= f.text_field :email %> +<%= f.password_field :password %> +<%= f.password_field :password_confirmation %> <% if @terms_of_use %> -

<%= @terms_of_use %>

-

<%= check_box_tag 'user[terms_accepted]' %> -

+

<%= @terms_of_use %>

+

<%= check_box_tag 'terms_accepted' %> +

<% end %>

<%= submit_tag 'Sign up' %>

-- libgit2 0.21.2