Skip to content

Commit

Permalink
Adding a rack now creates the right amount of units
Browse files Browse the repository at this point in the history
  • Loading branch information
Bob Van Landuyt committed Sep 29, 2010
1 parent 17f49dd commit 110b6ad
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 2 deletions.
4 changes: 3 additions & 1 deletion app/controllers/server_racks_controller.rb
Expand Up @@ -41,7 +41,9 @@ def edit
# POST /server_racks.xml
def create
@server_rack = ServerRack.new(params[:server_rack])

logger.debug(params[:server_rack])
1.upto(params[:number_of_units].to_i) {|i| logger.debug @server_rack.units << Unit.new(:number => i)}

respond_to do |format|
if @server_rack.save
format.html { redirect_to([@server_rack.datacenter, @server_rack], :notice => 'Server rack was successfully created.') }
Expand Down
2 changes: 1 addition & 1 deletion app/models/server_rack.rb
@@ -1,4 +1,4 @@
class ServerRack < ActiveRecord::Base
belongs_to :datacenter
has_many :units
has_many :units, :dependent => :destroy
end
4 changes: 4 additions & 0 deletions app/views/server_racks/_form.html.erb
Expand Up @@ -23,6 +23,10 @@
<%= f.label :comment %><br />
<%= f.text_field :comment %>
</div>
<div class="field">
<%= label 'number_of_units', :number_of_units %><br />
<%= text_field_tag :number_of_units %>
</div>
<div class="actions">
<%= f.submit %>
</div>
Expand Down

0 comments on commit 110b6ad

Please sign in to comment.