-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#125 - Register a group of participants on an invoice
- Loading branch information
Ivar Nilsen
committed
Oct 4, 2011
1 parent
932dcc9
commit f6f2245
Showing
8 changed files
with
99 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# -*- encoding : utf-8 -*- | ||
module InvoicesHelper | ||
def fields_for_user(user, &block) | ||
prefix = user.new_record? ? "new" : "existing" | ||
fields_for("invoice[#{prefix}_user_attributes][]", user, &block) | ||
end | ||
def add_user_link(text) | ||
link_to_function(text) do |page| | ||
page.insert_html :bottom, :users, :partial => "user", :object => User.new | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,40 @@ | ||
# -*- encoding : utf-8 -*- | ||
class Invoice < ActiveRecord::Base | ||
|
||
has_many :users | ||
has_many :users | ||
|
||
end | ||
def new_user_attributes=(user_attributes) | ||
user_attributes.each do |attributes| | ||
if attributes[:name].present? | ||
user = users.build attributes | ||
user.password = "dnmglksdngldsn" | ||
user.password_confirmation = user.password | ||
user.company = company_name | ||
user.registration = Registration.new | ||
user.registration.ticket_type = "early_bird" # TODO: Don't hardcode this | ||
user.registration.manual_payment = true | ||
# TODO @user.registration_ip = request.remote_ip | ||
end | ||
end | ||
end | ||
def existing_user_attributes=(user_attributes) | ||
users.reject(&:new_record?).each do |user| | ||
attributes = user_attributes[user.id.to_s] | ||
if attributes | ||
user.attributes = attributes | ||
else | ||
users.delete(user) | ||
end | ||
end | ||
end | ||
before_validation do | ||
for user in users | ||
user.company = self.company_name | ||
end | ||
end | ||
after_update do | ||
for user in users | ||
user.save(false) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<tr> | ||
<%= fields_for_user(user) do |user_form| %> | ||
<td><%= user_form.text_field :name %></td> | ||
<td><%= user_form.text_field :email %></td> | ||
<td><%= user_form.text_field :phone_number %></td> | ||
<td> | ||
<% if user.errors.any? %> | ||
<div id="error_explanation"> | ||
<ul> | ||
<% user.errors.full_messages.each do |msg| %> | ||
<li><%= msg %></li> | ||
<% end %> | ||
</ul> | ||
</div> | ||
<% end %> | ||
</td> | ||
<td> | ||
<%= link_to_function "slett", "$(this).closest('tr').remove()" %> | ||
</td> | ||
<% end %> | ||
</tr> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters