Permalink
Browse files

Hacked in a response form

  • Loading branch information...
CoryFoy committed Oct 30, 2011
1 parent fd98c17 commit 5b8c43f1d815baee55afc171451a4225c91ef97f
@@ -1,18 +0,0 @@
-class EventController < ApplicationController
- def new
- end
-
- def create
- @event = Event.create!(params[:event])
- end
-
- def show
- puts params[:token]
- @event = Event.first(conditions: {token: params[:token]})
- puts @event.inspect
- end
-
- def delete
- end
-
-end
@@ -0,0 +1,37 @@
+class EventsController < ApplicationController
+ def new
+ end
+
+ def create
+ event = Event.create!(params[:event])
+ flash[:notice] = "Your event has been created! You can access it at http://localhost:3000/e/#{event.token}"
+ redirect_to :action => "show", :id => event.token
+ end
+
+ def show
+ @event = Event.first(conditions: {token: params[:id]})
+ @counts = {:yes => 0, :no => 0, :maybe => 0}
+ @event.responses.each do |event_response|
+ case event_response.is_coming
+ when "Yes"
+ @counts[:yes] += 1
+ when "No"
+ @counts[:no] += 1
+ else
+ @counts[:maybe] += 1
+ end
+ end
+ end
+
+ def update
+ puts "****#{params[:event][:token]}*****"
+ event = Event.first(conditions: {token: params[:event][:token]})
+ event.responses.create!(params[:event][:response])
+ flash[:notice] = "Your response has been saved!"
+ redirect_to :action => "show", :id => event.token
+ end
+
+ def delete
+ end
+
+end
View
@@ -1,6 +1,7 @@
class Event
include UniquifyMongo::Uniquify
include Mongoid::Document
+ embeds_many :responses
unique_field :token
field :name
View
@@ -0,0 +1,9 @@
+class Response
+ include Mongoid::Document
+
+ field :is_coming
+ field :name
+ field :email
+ field :comments
+ embedded_in :event
+end
@@ -1,5 +0,0 @@
-<h1>Welcome to "<%=@event.name %>"!</h1>
-To be held on <b><%=@event.date %></b> at <em><%=@event.location %></em><br />
-Description: <br />
-<%=@event.description %>
-
@@ -0,0 +1,12 @@
+<div id="response_form">
+ <h2>Are you coming?</h2>
+ <%= parent_form.fields_for :response do |builder| %>
+ <%= builder.radio_button :is_coming, "Yes" %><%= builder.label :is_coming, "Yes" %>
+ <%= builder.radio_button :is_coming, "No" %><%= builder.label :is_coming, "No" %>
+ <%= builder.radio_button :is_coming, "Maybe", :checked => true %><%= builder.label :is_coming, "Maybe" %><br />
+ <%= builder.label :name, "Your Name:" %><%= builder.text_field :name %><br />
+ <%= builder.label :email, "Your Email Address:" %><%= builder.text_field :email %><br />
+ <%= builder.label :comments, "Comments:" %><br /><%= builder.text_area :comments %><br />
+ <%= builder.submit %>
+ <% end %>
+</div>
File renamed without changes.
File renamed without changes.
File renamed without changes.
@@ -0,0 +1,17 @@
+<%- flash.each do |key, msg| -%>
+ <div id="<%= key %>">
+ <p style="float:right;"><%= link_to_function 'X', "$('##{key}').fadeOut('slow', function(){})" %></p>
+ <p><%= msg %></p>
+ <div class="clear"></div>
+ </div>
+<%- end -%>
+
+<%= form_for @event do |f| %>
+ <%= f.hidden_field :token, :value => @event.token %>
+ <h1>Welcome to "<%=@event.name %>"!</h1>
+ Responses: <%=@counts[:yes] %> Yes, <%=@counts[:no] %> No, <%=@counts[:maybe] %> Maybe<br />
+To be held on <b><%=@event.date %></b> at <em><%=@event.location %></em><br />
+Description: <br />
+<%=@event.description %>
+<%= render :partial => 'response_form', :locals => {:parent_form => f} %>
+<% end %>
@@ -1,5 +1,5 @@
<h1>Respond to Us!</h1>
-<%= form_for @event, :url => event_create_path do |f| %>
+<%= form_for @event do |f| %>
<%= f.label :name, "Event Name:" %><%= f.text_field :name %> <br />
<%= f.label :date, "Event Date:" %><%= f.text_field :date %> <br />
View
@@ -1,12 +1,6 @@
Respondtous::Application.routes.draw do
- get "event/new"
-
- post "event/create"
-
- get "event/show"
-
- post "event/delete"
+ resources :events
devise_for :users
@@ -15,7 +9,6 @@
# Sample of regular route:
# match 'products/:id' => 'catalog#view'
- match 'event/:token' => 'event#show'
# Keep in mind you can assign values other than :controller and :action
# Sample of named route:
@@ -2,32 +2,32 @@
describe EventController do
- describe "GET 'new'" do
- it "returns http success" do
- get 'new'
- response.should be_success
- end
- end
+# describe "GET 'new'" do
+# it "returns http success" do
+# get 'new'
+# response.should be_success
+# end
+# end
- describe "GET 'create'" do
- it "returns http success" do
- get 'create'
- response.should be_success
- end
- end
+# describe "GET 'create'" do
+# it "returns http success" do
+# get 'create'
+# response.should be_success
+# end
+# end
- describe "GET 'show'" do
- it "returns http success" do
- get 'show'
- response.should be_success
- end
- end
+# describe "GET 'show'" do
+# it "returns http success" do
+# get 'show'
+# response.should be_success
+# end
+# end
- describe "GET 'delete'" do
- it "returns http success" do
- get 'delete'
- response.should be_success
- end
- end
+# describe "GET 'delete'" do
+# it "returns http success" do
+# get 'delete'
+# response.should be_success
+# end
+# end
end

0 comments on commit 5b8c43f

Please sign in to comment.