diff options
author | David Heinemeier Hansson <david@loudthinking.com> | 2004-12-16 19:43:27 +0000 |
---|---|---|
committer | David Heinemeier Hansson <david@loudthinking.com> | 2004-12-16 19:43:27 +0000 |
commit | 2f3db152ecbb76c9bcb5b2e3aa12816896df79f1 (patch) | |
tree | dd2e7378ea09f1ba2ce124a3c7b24ca8c47ac01f | |
parent | b64c26ad9db0c85fc21c34dde28ba747552f05c9 (diff) | |
download | rails-2f3db152ecbb76c9bcb5b2e3aa12816896df79f1.tar.gz rails-2f3db152ecbb76c9bcb5b2e3aa12816896df79f1.tar.bz2 rails-2f3db152ecbb76c9bcb5b2e3aa12816896df79f1.zip |
Made the last tweaks before 0.9
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@197 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
-rw-r--r-- | actionpack/lib/action_controller/templates/scaffolds/layout.rhtml | 36 | ||||
-rw-r--r-- | activerecord/lib/active_record/acts/list.rb | 115 | ||||
-rwxr-xr-x | activerecord/lib/active_record/validations.rb | 5 | ||||
-rw-r--r-- | railties/generators/scaffold/templates/controller.rb | 3 | ||||
-rw-r--r-- | railties/generators/scaffold/templates/functional_test.rb | 2 | ||||
-rw-r--r-- | railties/generators/scaffold/templates/style.css | 36 | ||||
-rw-r--r-- | railties/lib/dispatcher.rb | 4 |
7 files changed, 135 insertions, 66 deletions
diff --git a/actionpack/lib/action_controller/templates/scaffolds/layout.rhtml b/actionpack/lib/action_controller/templates/scaffolds/layout.rhtml index 511054abe8..77eecdf9d6 100644 --- a/actionpack/lib/action_controller/templates/scaffolds/layout.rhtml +++ b/actionpack/lib/action_controller/templates/scaffolds/layout.rhtml @@ -19,6 +19,42 @@ a { color: #000; } a:visited { color: #666; } a:hover { color: #fff; background-color:#000; } + + .fieldWithErrors { + padding: 2px; + background-color: red; + display: table; + } + + #ErrorExplanation { + width: 400px; + border: 2px solid #red; + padding: 7px; + padding-bottom: 12px; + margin-bottom: 20px; + background-color: #f0f0f0; + } + + #ErrorExplanation h2 { + text-align: left; + font-weight: bold; + padding: 5px 5px 5px 15px; + font-size: 12px; + margin: -7px; + background-color: #c00; + color: #fff; + } + + #ErrorExplanation p { + color: #333; + margin-bottom: 0; + padding: 5px; + } + + #ErrorExplanation ul li { + font-size: 12px; + list-style: square; + } </style> </head> <body> diff --git a/activerecord/lib/active_record/acts/list.rb b/activerecord/lib/active_record/acts/list.rb index bf4bd74597..626547f005 100644 --- a/activerecord/lib/active_record/acts/list.rb +++ b/activerecord/lib/active_record/acts/list.rb @@ -48,7 +48,7 @@ module ActiveRecord end before_destroy :remove_from_list - after_create :add_to_list_bottom + before_create :add_to_list_bottom EOV end end @@ -88,14 +88,6 @@ module ActiveRecord end - def add_to_list_top - increment_positions_on_all_items - end - - def add_to_list_bottom - assume_bottom_position - end - def remove_from_list decrement_positions_on_lower_items end @@ -119,58 +111,67 @@ module ActiveRecord end private - # Overwrite this method to define the scope of the list changes - def scope_condition() "1" end - - def higher_item - self.class.find_first( - "#{scope_condition} AND #{position_column} = #{(send(position_column).to_i - 1).to_s}" - ) - end + + def add_to_list_top + increment_positions_on_all_items + end + + def add_to_list_bottom + write_attribute(position_column, bottom_position_in_list.to_i + 1) + end + + # Overwrite this method to define the scope of the list changes + def scope_condition() "1" end + + def higher_item + self.class.find_first( + "#{scope_condition} AND #{position_column} = #{(send(position_column).to_i - 1).to_s}" + ) + end + + def lower_item + self.class.find_first( + "#{scope_condition} AND #{position_column} = #{(send(position_column).to_i + 1).to_s}" + ) + end + + def bottom_position_in_list + item = bottom_item + item ? item.send(position_column) : 0 + end + + def bottom_item + self.class.find_first( + "#{scope_condition} ", + "#{position_column} DESC" + ) + end + + def assume_bottom_position + update_attribute position_column, bottom_position_in_list.to_i + 1 + end - def lower_item - self.class.find_first( - "#{scope_condition} AND #{position_column} = #{(send(position_column).to_i + 1).to_s}" - ) - end + def assume_top_position + update_attribute position_column, 1 + end - def bottom_position_in_list - item = bottom_item - item ? item.send(position_column) : 0 - end + def decrement_positions_on_lower_items + self.class.update_all( + "#{position_column} = (#{position_column} - 1)", "#{scope_condition} AND #{position_column} > #{send(position_column).to_i}" + ) + end - def bottom_item - self.class.find_first( - "#{scope_condition} ", - "#{position_column} DESC" - ) - end - - def assume_bottom_position - update_attribute position_column, bottom_position_in_list.to_i + 1 - end - - def assume_top_position - update_attribute position_column, 1 - end - - def decrement_positions_on_lower_items - self.class.update_all( - "#{position_column} = (#{position_column} - 1)", "#{scope_condition} AND #{position_column} > #{send(position_column).to_i}" - ) - end - - def increment_positions_on_higher_items - self.class.update_all( - "#{position_column} = (#{position_column} + 1)", "#{scope_condition} AND #{position_column} < #{send(position_column)}" - ) - end + def increment_positions_on_higher_items + self.class.update_all( + "#{position_column} = (#{position_column} + 1)", "#{scope_condition} AND #{position_column} < #{send(position_column)}" + ) + end - def increment_positions_on_all_items - self.class.update_all( - "#{position_column} = (#{position_column} + 1)", "#{scope_condition}" - ) - end + def increment_positions_on_all_items + self.class.update_all( + "#{position_column} = (#{position_column} + 1)", "#{scope_condition}" + ) + end end end end diff --git a/activerecord/lib/active_record/validations.rb b/activerecord/lib/active_record/validations.rb index 19a15c26e0..af3285f04e 100755 --- a/activerecord/lib/active_record/validations.rb +++ b/activerecord/lib/active_record/validations.rb @@ -190,7 +190,6 @@ module ActiveRecord class_eval(%(#{validation_method(configuration[:on])} %{errors.add( '#{attr_name}', '#{msg}') if #{attr_name}.to_s.length != #{is} })) end end - end # Validates whether the value of the specified attributes are unique across the system. Useful for making sure that only one user @@ -401,8 +400,8 @@ module ActiveRecord # If the length is above the boundary, the too_long_msg message will be used. If below, the too_short_msg. def add_on_boundary_breaking(attributes, range, too_long_msg = @@default_error_messages[:too_long], too_short_msg = @@default_error_messages[:too_short]) for attr in [attributes].flatten - add(attr, too_short_msg % range.begin) if @base.attribute_present?(attr.to_s) && @base.send(attr.to_s).length < range.begin - add(attr, too_long_msg % range.end) if @base.attribute_present?(attr.to_s) && @base.send(attr.to_s).length > range.end + add(attr, too_short_msg % range.begin) if @base[attr.to_s] && @base.send(attr.to_s).length < range.begin + add(attr, too_long_msg % range.end) if @base[attr.to_s] && @base.send(attr.to_s).length > range.end end end diff --git a/railties/generators/scaffold/templates/controller.rb b/railties/generators/scaffold/templates/controller.rb index 83520f4794..15ade4c49b 100644 --- a/railties/generators/scaffold/templates/controller.rb +++ b/railties/generators/scaffold/templates/controller.rb @@ -1,6 +1,5 @@ class <%= class_name %>Controller < ApplicationController - model :<%= singular_name %> - layout 'scaffold' + layout 'scaffold' <% unless suffix -%> def index diff --git a/railties/generators/scaffold/templates/functional_test.rb b/railties/generators/scaffold/templates/functional_test.rb index b7315cfb84..1bf7d83694 100644 --- a/railties/generators/scaffold/templates/functional_test.rb +++ b/railties/generators/scaffold/templates/functional_test.rb @@ -62,7 +62,7 @@ class <%= class_name %>ControllerTest < Test::Unit::TestCase end def test_update<%= suffix %> - process :update<%= suffix %>, 'id' => 1 + process :update<%= suffix %>, '<%= singular_name %>' => { 'id' => 1 } assert_redirected_to :action => 'show<%= suffix %>', :id => 1 end diff --git a/railties/generators/scaffold/templates/style.css b/railties/generators/scaffold/templates/style.css index 2db43b7fa1..8f512501bf 100644 --- a/railties/generators/scaffold/templates/style.css +++ b/railties/generators/scaffold/templates/style.css @@ -15,3 +15,39 @@ pre { a { color: #000; } a:visited { color: #666; } a:hover { color: #fff; background-color:#000; } + +.fieldWithErrors { + padding: 2px; + background-color: red; + display: table; +} + +#ErrorExplanation { + width: 400px; + border: 2px solid #red; + padding: 7px; + padding-bottom: 12px; + margin-bottom: 20px; + background-color: #f0f0f0; +} + +#ErrorExplanation h2 { + text-align: left; + font-weight: bold; + padding: 5px 5px 5px 15px; + font-size: 12px; + margin: -7px; + background-color: #c00; + color: #fff; +} + +#ErrorExplanation p { + color: #333; + margin-bottom: 0; + padding: 5px; +} + +#ErrorExplanation ul li { + font-size: 12px; + list-style: square; +} diff --git a/railties/lib/dispatcher.rb b/railties/lib/dispatcher.rb index ceb88f30ba..25a898c530 100644 --- a/railties/lib/dispatcher.rb +++ b/railties/lib/dispatcher.rb @@ -24,9 +24,7 @@ require 'breakpoint' class Dispatcher - DEFAULT_SESSION_OPTIONS = { :database_manager => CGI::Session::PStore, :prefix => "ruby_sess.", :session_path => "/" } - - def self.dispatch(cgi = CGI.new, session_options = DEFAULT_SESSION_OPTIONS) + def self.dispatch(cgi = CGI.new, session_options = ActionController::CgiRequest.DEFAULT_SESSION_OPTIONS) Breakpoint.activate_drb("druby://localhost:#{BREAKPOINT_SERVER_PORT}", nil, !defined?(FastCGI)) if defined?(BREAKPOINT_SERVER_PORT) begin |