Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

er: first pass at rsvp functionality

  • Loading branch information...
commit 36c327c7ce73eea78aaa7e2336db5b5648c246d2 1 parent ea9bcd7
Eric Ryan authored
View
9 app/assets/stylesheets/application.css.scss
@@ -16,4 +16,13 @@
.hidden {
display: none;
+}
+
+.alert-message {
+ font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
+}
+
+.alert-message a {
+ font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
+ color: #fff;
}
View
0  app/assets/stylesheets/bootstrap.css → app/assets/stylesheets/bootstrap.css.scss
File renamed without changes
View
37 app/controllers/rsvp_controller.rb
@@ -5,12 +5,45 @@ def index
end
def create
- #flash[:notice] = 'RSVP successfully submitted!'
- flash[:notice] = params
+ if validate_primary params
+ primary = Rsvp.create! :title => params["primary_title"], :first_name => params["primary_first_name"], :last_name => params["primary_last_name"], :primary => true
+ guests = create_guests params, primary.id
+
+ flash[:notice] = "RSVP successfully submitted for #{params["primary_first_name"]} #{params["primary_last_name"]} and #{guests.size} guests. <br/> If you need to make any changes please <a href='mailto:aegeorge4@gmail.com'>email us</a> or call us (304-282-9260)."
+ else
+ flash[:error] = 'There was an error submitting your RSVP. All fields are required, except the Message. Please try again.'
+ #TODO - Airbrake
+ end
respond_to do |format|
format.html { redirect_to("/rsvp") }
end
end
+ def validate_primary params
+ validate("primary",params) && !params["primary_email"].empty? && !params["primary_phone"].empty?
+ end
+
+ def validate prefix="primary", params
+ logger.info "validating #{prefix}"
+ !params["#{prefix}_title"].empty? &&
+ !params["#{prefix}_first_name"].empty? &&
+ !params["#{prefix}_last_name"].empty?
+ end
+
+ def create_guests params, primary_id
+ guests = []
+ 1.upto(10) do |guest_num|
+ if validate "#{guest_num}_guest", params
+ guest = Rsvp.create! :title => params["#{guest_num}_guest_title"],
+ :first_name => params["#{guest_num}_guest_first_name"],
+ :last_name => params["#{guest_num}_guest_last_name"],
+ :primary => false,
+ :guest_of_id => primary_id
+ guests << guest
+ end
+ end
+ guests
+ end
+
end
View
3  app/models/rsvp.rb
@@ -1,2 +1,5 @@
class Rsvp < ActiveRecord::Base
+
+
+
end
View
8 app/views/rsvp/_guest.html.erb
@@ -1,9 +1,9 @@
<% @number_str = number_to_word number %>
<div class="clearfix hidden <%= @class_string %>">
- <%= label_tag(:name, "#{@number_str.capitalize} Guest", :class => 'span5') %>
- <%= text_field_tag("#{@number_str}_guest_title".to_sym, nil, :class => 'input span1', :placeholder => 'Mrs.') %>
- <%= text_field_tag("#{@number_str}_guest_first_name".to_sym, nil, :class => 'input span3', :placeholder => 'First') %>
- <%= text_field_tag("#{@number_str}_guest_last_name".to_sym, nil, :class => 'input span3', :placeholder => 'Last') %>
+ <%= label_tag(:name, "#{number} Guest", :class => 'span5') %>
+ <%= text_field_tag("#{number}_guest_title".to_sym, nil, :class => 'input span1', :placeholder => 'Mrs.') %>
+ <%= text_field_tag("#{number}_guest_first_name".to_sym, nil, :class => 'input span3', :placeholder => 'First') %>
+ <%= text_field_tag("#{number}_guest_last_name".to_sym, nil, :class => 'input span3', :placeholder => 'Last') %>
<%= tag "input", {:type => "button", :value => "x", :onclick => "removeGuest()", :class => 'btn small danger span1', :id => 'remove_guest_button'} %>
</div>
View
2  app/views/rsvp/index.html.erb
@@ -54,7 +54,7 @@
<div class="clearfix">
<%= label_tag(:message, "Message", :class => 'span5') %>
- <%= text_area_tag(:message, nil, :class => 'input span7', :placeholder => "I can't wait to moonwalk at your wedding!", :size => '20x6') %>
+ <%= text_area_tag(:message, nil, :class => 'input span7', :placeholder => "I can't wait to moonwalk at your wedding! (optional)", :size => '20x6') %>
</div>
<div class="row">
View
6 app/views/shared/_flashes.html.erb
@@ -1,17 +1,17 @@
<% unless flash[:notice].blank? %>
<div class="alert-message info">
- <%= content_tag :div, flash[:notice] %>
+ <%= content_tag :div, flash[:notice].html_safe %>
</div>
<% end %>
<% unless flash[:error].blank? %>
<div class="alert-message error">
- <%= content_tag :div, flash[:error] %>
+ <%= content_tag :div, flash[:error].html_safe %>
</div>
<% end %>
<% unless flash[:alert].blank? %>
<div class="alert-message warning">
- <%= content_tag :div, flash[:alert] %>
+ <%= content_tag :div, flash[:alert].html_safe %>
</div>
<% end %>
View
4 db/schema.rb
@@ -11,13 +11,13 @@
#
# It's strongly recommended to check this file into your version control system.
-ActiveRecord::Schema.define(:version => 20111126052252) do
+ActiveRecord::Schema.define(:version => 20120223033815) do
create_table "rsvps", :force => true do |t|
+ t.string "title"
t.string "first_name"
t.string "last_name"
t.boolean "primary"
- t.integer "number_of_guests"
t.integer "guest_of_id"
t.datetime "created_at"
t.datetime "updated_at"
Please sign in to comment.
Something went wrong with that request. Please try again.