Made the last tweaks before 0.9

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@197 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
This commit is contained in:
David Heinemeier Hansson
2004-12-16 19:43:27 +00:00
parent b64c26ad9d
commit 2f3db152ec
7 changed files with 137 additions and 68 deletions

View File

@@ -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>

View File

@@ -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 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 add_to_list_top
increment_positions_on_all_items
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 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 increment_positions_on_all_items
self.class.update_all(
"#{position_column} = (#{position_column} + 1)", "#{scope_condition}"
)
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 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_all_items
self.class.update_all(
"#{position_column} = (#{position_column} + 1)", "#{scope_condition}"
)
end
end
end
end

View File

@@ -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

View File

@@ -1,6 +1,5 @@
class <%= class_name %>Controller < ApplicationController
model :<%= singular_name %>
layout 'scaffold'
layout 'scaffold'
<% unless suffix -%>
def index

View File

@@ -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

View File

@@ -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;
}

View File

@@ -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