Skip to content

Commit

Permalink
Terrible way of deleting users from invoice
Browse files Browse the repository at this point in the history
  • Loading branch information
Ivar Nilsen committed Oct 4, 2011
1 parent a9d15ef commit 932dcc9
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 4 deletions.
7 changes: 5 additions & 2 deletions app/controllers/invoices_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,12 @@ def create

def update
@invoice = Invoice.find(params[:id])

respond_to do |format|
if @invoice.update_attributes(params[:invoice])
@invoice.update_attributes(params[:invoice])
for user in params[:deleted_users] || []
@invoice.users.delete(@invoice.users.find(user.to_i))
end
if @invoice.save
format.html { redirect_to(@invoice, :notice => 'Invoice was successfully updated.') }
else
format.html { render :action => "edit" }
Expand Down
9 changes: 9 additions & 0 deletions app/views/invoices/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,14 @@
<%= f.submit %>
</div>

<ul>
<% @invoice.users.each do |user| %>
<li>
<div><%= user.name %></div>
<input type="checkbox" name="deleted_users[]" value="<%= user.id %>"/>
</li>
<% end %>
</ul>

</fieldset>
<% end %>
2 changes: 1 addition & 1 deletion db/migrate/20111004170407_create_invoices.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ def self.up
t.string :contact_email
t.string :contact_person
t.string :street_address
t.integer :post_code
t.string :post_code

t.timestamps
end
Expand Down
2 changes: 1 addition & 1 deletion db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
t.string "contact_email"
t.string "contact_person"
t.string "street_address"
t.integer "post_code"
t.string "post_code"
t.datetime "created_at"
t.datetime "updated_at"
end
Expand Down

0 comments on commit 932dcc9

Please sign in to comment.