Skip to content

Commit

Permalink
Merge branch 'master' of github.com:lilykuang/Fall14HKSA
Browse files Browse the repository at this point in the history
  • Loading branch information
luisingho committed Sep 3, 2014
2 parents d19e444 + 2332d20 commit 08aec4a
Show file tree
Hide file tree
Showing 37 changed files with 303 additions and 57 deletions.
3 changes: 3 additions & 0 deletions app/assets/javascripts/sponsors.js.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Place all the behaviors and hooks related to the matching controller here.
# All this logic will automatically be available in application.js.
# You can use CoffeeScript in this file: http://coffeescript.org/
3 changes: 3 additions & 0 deletions app/assets/stylesheets/sponsors.css.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// Place all the styles related to the sponsors controller here.
// They will automatically be included in application.css.
// You can use Sass (SCSS) here: http://sass-lang.com/
9 changes: 9 additions & 0 deletions app/assets/stylesheets/users.css.scss
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
// Place all the styles related to the Users controller here.
// They will automatically be included in application.css.
// You can use Sass (SCSS) here: http://sass-lang.com/
#error_explanation {
color: #f00;
ul {
list-style: none;
margin: 0 0 18px 0;
}
}


30 changes: 26 additions & 4 deletions app/controllers/officers_controller.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,28 @@
class OfficersController < ApplicationController
VALID_EMAIL_REGEX = /\A[\w+\-.]+@[a-z\d\-.]+\.[a-z]+\z/i
validates :email, presence: true,
format: { with: VALID_EMAIL_REGEX },
uniqueness: { case_sensitive: false }

def new
@officer = Officer.new
end

def create
@officer = Officer.new(officer_params)
if @officer.save
redirect_to officers_path
else
render 'new'
end
end

def index
@officer = Officer.all
end

private

def officer_params
params.require(:officer).permit(:firstName,
:lastName, :year, :position,
:major, :description)
end

end
32 changes: 32 additions & 0 deletions app/controllers/sponsors_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
class SponsorsController < ApplicationController
def index
@sponsors = Sponsor.all
end

def new
@sponsor = Sponsor.new
end

def show
@sponsor = Sponsor.find(params[:id])
end

def create
@sponsor = Sponsor.new(sponsor_params)
if @sponsor.save
redirect_to @sponsor
else
render 'new'
end
end

def edit
@sponsor = Sponsor.find(params[:id])
end

private

def sponsor_params
params.require(:sponsor).permit(:name, :address, :advertisement)
end
end
2 changes: 2 additions & 0 deletions app/helpers/sponsors_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
module SponsorsHelper
end
3 changes: 1 addition & 2 deletions app/models/front_page.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
class FrontPage < ActiveRecord::Base
has_many: officers
has_many: sponsors
has_many :sponsors
end
3 changes: 3 additions & 0 deletions app/models/sponsor.rb
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
class Sponsor < ActiveRecord::Base
belongs_to :front_page
validates :name, presence: true, length: { maximum: 50 }
validates :address, presence: true, length: { maximum: 50 }
end
8 changes: 5 additions & 3 deletions app/views/events/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@

<nav>
<%= link_to "All Events", events_path %> |
<% if current_user.admin? && !current_user?(user) %>
<%= link_to "Edit", edit_event_path(@event) %>
<% end -%>
<% if current_user %>
<% if current_user.admin? && !current_user?(user) %>
<%= link_to "Edit", edit_event_path(@event) %>
<% end %>
<% end %>
</nav>
14 changes: 8 additions & 6 deletions app/views/members/index.html.erb
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
<li><%= link_to 'Home', root_path %></li>
<% if current_user.admin? && !current_user?(user) %>
<h1>All Subscription</h1>
<% @members.each do |member| %>
<li><%= member.name %></br>
<%= member.email %></li>
<% if current_user %>
<% if current_user.admin? %>
<h1>All Subscription</h1>
<% @members.each do |member| %>
<li><%= member.name %> <%= member.email %>
| <%= link_to "delete", member, method: :delete,
data: { confirm: "You sure?" } %></li>
<% end %>
<% end %>
<% end %>
8 changes: 5 additions & 3 deletions app/views/members/new.html.erb
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
<div>
<div>
<%= form_for(@member) do |f| %>

<%= render 'shared/subscription_error' %>
<p>
<%= f.label :name %>
<%= f.text_field :name %>

</p>
<p>
<%= f.label :email %>
<%= f.text_field :email %>

</p>
<%= f.submit "Subscribe us" %>
<% end %>
</div>
Expand Down
15 changes: 15 additions & 0 deletions app/views/officers/index.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@

<% @officer.each do |officer| %>
<h3><%= officer.firstName %> <%= officer.lastName %></h3>
<li><%= officer.year %></li>
<li><%= officer.position %></li>
<li><%= officer.major %></li>
<li><%= officer.description %>
<% if current_user %>
<% if current_user.admin? %>
| <%= link_to "delete", officer, method: :delete,
data: { confirm: "You sure?" } %>
<% end %>
<% end %></li>

<% end %>
30 changes: 30 additions & 0 deletions app/views/officers/new.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<h1>Add Officer</h1>
<%= form_for @officer do |f| %>
<p>
<%= f.label :firstName %><br/>
<%= f.text_field :firstName %>
</p>
<p>
<%= f.label :lastName %><br/>
<%= f.text_field :lastName %>
</p>
<p>
<%= f.label :year %><br/>
<%= f.text_field :year %>
</p>
<p>
<%= f.label :position %><br/>
<%= f.text_field :position %>
</p>
<p>
<%= f.label :major %><br/>
<%= f.text_field :major %>
</p>
<p>
<%= f.label :description %><br/>
<%= f.text_area :description, cols: 40, rows: 7 %>
</p>
<p>
<%= f.submit %>
</p>
<% end %>
1 change: 0 additions & 1 deletion app/views/sessions/new.html.erb
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<% provide(:title, "Sign in") %>
<h1>Sign in</h1>

<div>
<div>
<%= form_for(:session, url: sessions_path) do |f| %>
Expand Down
12 changes: 12 additions & 0 deletions app/views/shared/_error_messages.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<% if @user.errors.any? %>
<div id="error_explanation">
<div class="alert alert-error">
The form contains <%= pluralize(@user.errors.count, "error") %>.
</div>
<ul>
<% @user.errors.full_messages.each do |msg| %>
<li>* <%= msg %></li>
<% end %>
</ul>
</div>
<% end %>
12 changes: 12 additions & 0 deletions app/views/shared/_sponsor_error.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<% if @sponsor.errors.any? %>
<div id="error_explanation">
<div class="alert alert-error">
The form contains <%= pluralize(@sponsor.errors.count, "error") %>.
</div>
<ul>
<% @sponsor.errors.full_messages.each do |msg| %>
<li>* <%= msg %></li>
<% end %>
</ul>
</div>
<% end %>
12 changes: 12 additions & 0 deletions app/views/shared/_subscription_error.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<% if @member.errors.any? %>
<div id="error_explanation">
<div class="alert alert-error">
The form contains <%= pluralize(@member.errors.count, "error") %>.
</div>
<ul>
<% @member.errors.full_messages.each do |msg| %>
<li>* <%= msg %></li>
<% end %>
</ul>
</div>
<% end %>
16 changes: 16 additions & 0 deletions app/views/sponsors/new.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<div>
<div>
<%= form_for(@sponsor) do |f| %>
<%= render 'shared/sponsor_error' %>
<p>
<%= f.label :name %>
<%= f.text_field :name %>
</p>
<p>
<%= f.label :address %>
<%= f.text_field :address %>
</p>
<%= f.submit %>
<% end %>
</div>
</div>
4 changes: 3 additions & 1 deletion app/views/users/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@
<ul class="users">
<% @users.each do |user| %>
<li>
<%= user.name %>
<%= link_to (user.name, user) %>
<% if current_user %>
<% if current_user.admin? && !current_user?(user) %>
| <%= link_to "delete", user, method: :delete,
data: { confirm: "You sure?" } %>
<% end %>
<% end %>
</li>
<% end %>
</ul>
7 changes: 6 additions & 1 deletion app/views/users/show.html.erb
Original file line number Diff line number Diff line change
@@ -1,2 +1,7 @@
<%= @user.name %>
<%= link_to "Sign out", signout_path, method: "delete" %>
<%= link_to "Sign out", signout_path, method: "delete" %></br>
<% if current_user.admin? %>
<%= link_to "Add New Event", new_event_path %></br>
<%= link_to "Add New Officer", new_officer_path %></br>
<%= link_to "Add New Sponsor", new_sponsor_path %>
<% end %>
20 changes: 12 additions & 8 deletions config/routes.rb
Original file line number Diff line number Diff line change
@@ -1,17 +1,21 @@
Rails.application.routes.draw do
#front_page
root 'front_pages#index'

resource :front_page, only: [:index]
resource :front_page, only: [:index]
resources :users
resources :officers
resources :events
resources :sponsors
resources :sessions, only: [:new, :create, :destroy]
resources :members, only: [:show,:new, :create, :destroy]
resources :members

#officer login
match '/signup', to: 'users#new', via: 'get'
match '/signin', to: 'sessions#new', via: 'get'
match '/signout', to: 'sessions#destroy', via: 'delete'
match '/member_signup', to:'members#new', via: 'get'
match '/about/', to: 'front_pages#index', via: 'get'
match '/signup', to: 'users#new', via: 'get'
match '/signin', to: 'sessions#new', via: 'get'
match '/signout', to: 'sessions#destroy', via: 'delete'

#Subscribe us
match '/subscribe', to: 'members#new', via: 'get'
match '/about/', to: 'front_pages#index', via: 'get'

end
Binary file modified db/development.sqlite3
Binary file not shown.
6 changes: 6 additions & 0 deletions db/migrate/20140823213155_remove_first_name_from_member.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
class RemoveFirstNameFromMember < ActiveRecord::Migration
def change
remove_column :members, :firstName, :string
remove_column :members, :lastName, :string
end
end
5 changes: 5 additions & 0 deletions db/migrate/20140823213307_add_name_to_member.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddNameToMember < ActiveRecord::Migration
def change
add_column :members, :name, :string
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class RemoveOfficerIdFromFrontPage < ActiveRecord::Migration
def change
remove_column :front_pages, :officer_id, :integer
end
end
5 changes: 5 additions & 0 deletions db/migrate/20140902003315_add_is_current_to_events.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddIsCurrentToEvents < ActiveRecord::Migration
def change
add_column :events, :isCurrent, :boolean
end
end
7 changes: 3 additions & 4 deletions db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema.define(version: 20140823211632) do
ActiveRecord::Schema.define(version: 20140902003315) do

create_table "event_pages", force: true do |t|
t.integer "pastEvent_id"
Expand All @@ -34,11 +34,11 @@
t.integer "avatar_file_size"
t.datetime "avatar_updated_at"
t.string "flyer"
t.boolean "isCurrent"
end

create_table "front_pages", force: true do |t|
t.string "calendar"
t.integer "officer_id"
t.integer "sponsor_id"
t.integer "currentEvent_id"
t.datetime "created_at"
Expand All @@ -47,10 +47,9 @@

create_table "members", force: true do |t|
t.string "email"
t.string "firstName"
t.string "lastName"
t.datetime "created_at"
t.datetime "updated_at"
t.string "name"
end

create_table "miscs", force: true do |t|
Expand Down
Binary file modified db/test.sqlite3
Binary file not shown.
10 changes: 10 additions & 0 deletions lib/tasks/sample_data.rake
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
namespace :db do
desc "Fill database with sample data"
task populate: :environment do
admin = User.create!(name: "Lily Kuang",
email: "[email protected]",
password: "19920725",
password_confirmation: "19920725",
admin: true)
end
end
Loading

0 comments on commit 08aec4a

Please sign in to comment.