diff --git a/app/controllers/teams_controller.rb b/app/controllers/teams_controller.rb index 2f1473d..7fb5689 100644 --- a/app/controllers/teams_controller.rb +++ b/app/controllers/teams_controller.rb @@ -5,22 +5,22 @@ class TeamsController < ApplicationController end def create - if current_person.blessed? - team = Team.create params[:team] - redirect_to "/teams/#{team.slug}" + @teams = current_person.teams + @team = Team.new params[:team].merge creator: current_person + if @team.save + redirect_to "/teams/#{@team.slug}" else - redirect_to :teams + render :index end end def add - if current_person.blessed? - team = Team.find_by_slug params[:slug] + with_team do |team| person = Person.find_by_email params[:email] person = Person.create email: params[:email] unless person Membership.create team: team, person: person + redirect_to "/teams/#{team.slug}" end - redirect_to "/teams/#{team.slug}" end def show @@ -43,7 +43,7 @@ private def with_team *args @team = Team.find_by_slug params[:slug] unless current_person.blessed? - @team = nil unless current_person.teams.include? @team + @team = nil unless current_person.teams.include?(@team) or @team.creator == current_person end if @team yield @team diff --git a/app/models/team.rb b/app/models/team.rb index b3ce5f3..7bc8cad 100644 --- a/app/models/team.rb +++ b/app/models/team.rb @@ -1,6 +1,11 @@ class Team < ActiveRecord::Base - attr_accessible :description, :name, :slug + attr_accessible :description, :name, :slug, :creator + + validates_presence_of :name + validates_presence_of :slug + validates_uniqueness_of :slug has_many :memberships has_many :people, through: :memberships -end + belongs_to :creator, class_name: 'Person' +end \ No newline at end of file diff --git a/app/views/teams/index.html.slim b/app/views/teams/index.html.slim index 64d58b6..dbdb4da 100644 --- a/app/views/teams/index.html.slim +++ b/app/views/teams/index.html.slim @@ -1,10 +1,9 @@ -- if @person.blessed? - div.row - div.offset3 - = form_for @team, html: {class: 'form-inline'} do |form| - = form.text_field :slug, placeholder: 'slug' - = form.text_field :name, placeholder: 'Team Name' - = form.submit 'Create', class: 'btn' +div.row + div.offset3 + = form_for @team, html: {class: 'form-inline'} do |form| + = form.text_field :slug, placeholder: 'slug' + = form.text_field :name, placeholder: 'Team Name' + = form.submit 'Create', class: 'btn' - @teams.each do |team| a href="/teams/#{team.slug}" diff --git a/app/views/teams/show.html.slim b/app/views/teams/show.html.slim index 54712ec..4521aff 100644 --- a/app/views/teams/show.html.slim +++ b/app/views/teams/show.html.slim @@ -4,12 +4,11 @@ li = link_to 'quiz', "/quiz/#{@team.slug}" -- if @person.blessed? - div.row - div.offset3 - = form_tag "/teams/#{@team.slug}/add", class: 'form-inline' do - = text_field_tag :email, nil, placeholder: 'email' - = submit_tag 'add', class: 'btn' +div.row + div.offset3 + = form_tag "/teams/#{@team.slug}/add", class: 'form-inline' do + = text_field_tag :email, nil, placeholder: 'email' + = submit_tag 'add', class: 'btn' - @team.memberships.each do |membership| div.hero-unit diff --git a/db/migrate/20120902015738_add_creator_to_team.rb b/db/migrate/20120902015738_add_creator_to_team.rb new file mode 100644 index 0000000..5d60251 --- /dev/null +++ b/db/migrate/20120902015738_add_creator_to_team.rb @@ -0,0 +1,5 @@ +class AddCreatorToTeam < ActiveRecord::Migration + def change + add_column :teams, :creator_id, :integer + end +end diff --git a/db/schema.rb b/db/schema.rb index 9995683..80880f0 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended to check this file into your version control system. -ActiveRecord::Schema.define(:version => 20120901061532) do +ActiveRecord::Schema.define(:version => 20120902015738) do create_table "facts", :force => true do |t| t.integer "person_id" @@ -54,6 +54,7 @@ ActiveRecord::Schema.define(:version => 20120901061532) do t.datetime "created_at", :null => false t.datetime "updated_at", :null => false t.string "slug" + t.integer "creator_id" end end