From 3cb26e9cb3c1f3a069e7654988c650ca12322ede Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Sun, 12 Jun 2005 05:33:23 +0000 Subject: r2495@sedna: jeremy | 2005-05-27 22:07:18 -0700 Branch to have scaffold use new render methods r2496@sedna: jeremy | 2005-05-28 10:50:51 -0700 axe unused process_request method r2497@sedna: jeremy | 2005-05-28 10:51:58 -0700 sanity assertions in process method check that @controller, @request, @response are set r2498@sedna: jeremy | 2005-05-28 10:53:42 -0700 clean up escaping. use instance_variable_get instead of instance_eval. put id in form action instead of hidden input (like the generated scaffolding) r2499@sedna: jeremy | 2005-05-28 10:54:46 -0700 clean up interpolation, remove tabs from stylesheet r2500@sedna: jeremy | 2005-05-28 10:56:40 -0700 modernize dynamic scaffolding. use params[:id] instead of @params[id]. use consolidated render method instead of render_action, render_file, etc. use builtin inflections rather than module methods. r2501@sedna: jeremy | 2005-05-28 11:00:26 -0700 modernize generated scaffolding. use new-style assertions; use params[:id] instead of @params[id]; use consolidated render method instead of render_* r2542@sedna: jeremy | 2005-06-12 02:24:06 -0700 use :id => model instead of :id => model.id. clean up the form helper method. use flash[:notice] instead of flash['notice']. r2543@sedna: jeremy | 2005-06-12 02:33:22 -0700 whitespace r2544@sedna: jeremy | 2005-06-12 02:56:57 -0700 update changelogs r2545@sedna: jeremy | 2005-06-12 03:26:23 -0700 test dynamic form help when @post is not a new record r2546@sedna: jeremy | 2005-06-12 03:44:14 -0700 touch up TestCase#process sanity assertions git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@1404 5ecf4fe2-1ee6-0310-87b1-e25e094e27de --- .../action_view/helpers/active_record_helper.rb | 26 ++++++++++++---------- 1 file changed, 14 insertions(+), 12 deletions(-) (limited to 'actionpack/lib/action_view') diff --git a/actionpack/lib/action_view/helpers/active_record_helper.rb b/actionpack/lib/action_view/helpers/active_record_helper.rb index f8a003e948..deb3effb1c 100644 --- a/actionpack/lib/action_view/helpers/active_record_helper.rb +++ b/actionpack/lib/action_view/helpers/active_record_helper.rb @@ -56,20 +56,22 @@ module ActionView # form << content_tag("b", "Department") # form << collection_select("department", "id", @departments, "id", "name") # end - def form(record_name, options = nil) - options = (options || {}).symbolize_keys - record = instance_eval("@#{record_name}") + def form(record_name, options = {}) + record = instance_variable_get("@#{record_name}") + options = options.symbolize_keys options[:action] ||= record.new_record? ? "create" : "update" - action = url_for(:action => options[:action]) + action = url_for(:action => options[:action], :id => record) submit_value = options[:submit_value] || options[:action].gsub(/[^\w]/, '').capitalize - id_field = record.new_record? ? "" : InstanceTag.new(record_name, "id", self).to_input_field_tag("hidden") + contents = '' + contents << hidden_field(record_name, :id) unless record.new_record? + contents << all_input_tags(record, record_name, options) + yield contents if block_given? + contents << submit_tag(submit_value) - formtag = %(
#{id_field}) + all_input_tags(record, record_name, options) - yield formtag if block_given? - formtag + %(
) + content_tag('form', contents, :action => action, :method => 'post') end # Returns a string containing the error message attached to the +method+ on the +object+, if one exists. @@ -83,8 +85,8 @@ module ActionView # <%= error_message_on "post", "title", "Title simply ", " (or it won't work)", "inputError" %> => #
Title simply can't be empty (or it won't work)
def error_message_on(object, method, prepend_text = "", append_text = "", css_class = "formError") - if errors = instance_eval("@#{object}").errors.on(method) - "
#{prepend_text + (errors.is_a?(Array) ? errors.first : errors) + append_text}
" + if errors = instance_variable_get("@#{object}").errors.on(method) + content_tag("div", "#{prepend_text}#{errors.is_a?(Array) ? errors.first : errors}#{append_text}", :class => css_class) end end @@ -96,7 +98,7 @@ module ActionView # * class - The class of the error div (default: errorExplanation) def error_messages_for(object_name, options = {}) options = options.symbolize_keys - object = instance_eval "@#{object_name}" + object = instance_variable_get("@#{object_name}") unless object.errors.empty? content_tag("div", content_tag( @@ -117,7 +119,7 @@ module ActionView end def default_input_block - Proc.new { |record, column| "


#{input(record, column.name)}

" } + Proc.new { |record, column| %(


#{input(record, column.name)}

) } end end -- cgit v1.2.3