Merge pull request #14 from ignisf/conference-slug-in-url
Put current conference in url
This commit is contained in:
commit
f173f42834
|
@ -1,21 +1,13 @@
|
||||||
module Management
|
module Management
|
||||||
class CallForParticipationsController < ManagementController
|
class CallForParticipationsController < ManagementController
|
||||||
before_action :assign_conference
|
|
||||||
|
|
||||||
def create
|
def create
|
||||||
@conference.call_for_participation.open!
|
current_conference.call_for_participation.open!
|
||||||
render :redraw
|
render :redraw
|
||||||
end
|
end
|
||||||
|
|
||||||
def destroy
|
def destroy
|
||||||
@conference.call_for_participation.close!
|
current_conference.call_for_participation.close!
|
||||||
render :redraw
|
render :redraw
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
|
||||||
|
|
||||||
def assign_conference
|
|
||||||
@conference = Conference.find params[:conference_id]
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -10,8 +10,7 @@ module Management
|
||||||
@conference = Conference.new(conference_params)
|
@conference = Conference.new(conference_params)
|
||||||
|
|
||||||
if @conference.save
|
if @conference.save
|
||||||
set_current_conference(@conference)
|
redirect_to management_conference_path(@conference, current_conference: @conference.slug)
|
||||||
redirect_to [:management, @conference]
|
|
||||||
else
|
else
|
||||||
render :new
|
render :new
|
||||||
end
|
end
|
||||||
|
@ -39,9 +38,8 @@ module Management
|
||||||
def destroy
|
def destroy
|
||||||
@conference = find_conference
|
@conference = find_conference
|
||||||
@conference.destroy
|
@conference.destroy
|
||||||
set_current_conference(nil)
|
|
||||||
|
|
||||||
redirect_to management_root_path
|
redirect_to management_root_path(current_conference: nil)
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
|
@ -5,9 +5,7 @@ module Management
|
||||||
|
|
||||||
def set_conference
|
def set_conference
|
||||||
conference = Conference.find(params[:id])
|
conference = Conference.find(params[:id])
|
||||||
set_current_conference(conference)
|
redirect_to management_conference_path(conference, current_conference: conference.slug)
|
||||||
|
|
||||||
redirect_to [:management, conference]
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -6,24 +6,25 @@ module Management
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
|
def default_url_options(options = {})
|
||||||
|
{ current_conference: current_conference.try(:slug) }.merge(options)
|
||||||
|
end
|
||||||
|
|
||||||
def current_conference?
|
def current_conference?
|
||||||
current_conference.present?
|
current_conference.present?
|
||||||
end
|
end
|
||||||
helper_method :current_conference?
|
helper_method :current_conference?
|
||||||
|
|
||||||
def current_conference
|
def current_conference
|
||||||
@current_conference ||= (session[:current_conference_id] and Conference.find_by(id: session[:current_conference_id]))
|
@current_conference ||=
|
||||||
|
begin
|
||||||
|
if params[:current_conference]
|
||||||
|
Conference.find_by_slug(params[:current_conference])
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
helper_method :current_conference
|
helper_method :current_conference
|
||||||
|
|
||||||
def set_current_conference(conference)
|
|
||||||
if conference.present?
|
|
||||||
session[:current_conference_id] = conference.id
|
|
||||||
else
|
|
||||||
session.delete(:current_conference_id)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def authorize_user!
|
def authorize_user!
|
||||||
head :forbidden unless current_user.admin?
|
head :forbidden unless current_user.admin?
|
||||||
end
|
end
|
||||||
|
|
|
@ -16,6 +16,7 @@ class Conference < ActiveRecord::Base
|
||||||
|
|
||||||
accepts_nested_attributes_for :tracks, :halls, reject_if: :all_blank, allow_destroy: true
|
accepts_nested_attributes_for :tracks, :halls, reject_if: :all_blank, allow_destroy: true
|
||||||
|
|
||||||
|
before_create :slugify_title
|
||||||
after_create :create_call_for_participation
|
after_create :create_call_for_participation
|
||||||
|
|
||||||
def submissions_grouped_by_day
|
def submissions_grouped_by_day
|
||||||
|
@ -28,6 +29,14 @@ class Conference < ActiveRecord::Base
|
||||||
submissions.group_by { |s| s.confirmed_at.to_date }
|
submissions.group_by { |s| s.confirmed_at.to_date }
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def self.find_by_slug(slug)
|
||||||
|
find_by(slug: slug)
|
||||||
|
end
|
||||||
|
|
||||||
|
def slugify_title
|
||||||
|
self.slug = title.gsub(/\s+/, '-')
|
||||||
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def start_date_is_before_end_date
|
def start_date_is_before_end_date
|
||||||
|
|
|
@ -7,14 +7,17 @@ Rails.application.routes.draw do
|
||||||
put '/set_conference/:id', to: 'home#set_conference', as: :set_conference
|
put '/set_conference/:id', to: 'home#set_conference', as: :set_conference
|
||||||
|
|
||||||
resources :conferences
|
resources :conferences
|
||||||
resources :events
|
|
||||||
resources :volunteers
|
|
||||||
resources :sponsorship_offers
|
|
||||||
resource :call_for_participation, only: [:create, :destroy]
|
|
||||||
|
|
||||||
resources :users do
|
scope ':current_conference' do
|
||||||
member do
|
resources :events
|
||||||
put :toggle_admin
|
resources :volunteers
|
||||||
|
resources :sponsorship_offers
|
||||||
|
resource :call_for_participation, only: [:create, :destroy]
|
||||||
|
|
||||||
|
resources :users do
|
||||||
|
member do
|
||||||
|
put :toggle_admin
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -6,7 +6,10 @@ end
|
||||||
|
|
||||||
class PopulateConferenceIdInPersonalProfiles < ActiveRecord::Migration
|
class PopulateConferenceIdInPersonalProfiles < ActiveRecord::Migration
|
||||||
def change
|
def change
|
||||||
conference = Conference.first!
|
conference = Conference.first
|
||||||
PersonalProfile.where(conference_id: nil).update_all(conference_id: conference.id)
|
|
||||||
|
if conference
|
||||||
|
PersonalProfile.where(conference_id: nil).update_all(conference_id: conference.id)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -0,0 +1,6 @@
|
||||||
|
class AddSlugToConferences < ActiveRecord::Migration
|
||||||
|
def change
|
||||||
|
add_column :conferences, :slug, :string
|
||||||
|
add_index :conferences, :slug
|
||||||
|
end
|
||||||
|
end
|
|
@ -0,0 +1,13 @@
|
||||||
|
class CreateSlugsForExistingConferences < ActiveRecord::Migration
|
||||||
|
class Conference < ActiveRecord::Base
|
||||||
|
end
|
||||||
|
|
||||||
|
def change
|
||||||
|
Globalize.with_locale(:en) do
|
||||||
|
Conference.find_each do |c|
|
||||||
|
c.slug = c.title.gsub(/\s+/, '-')
|
||||||
|
c.save!
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
|
@ -8,7 +8,7 @@ RSpec.describe Management::CallForParticipationsController, type: :controller do
|
||||||
describe 'POST #create' do
|
describe 'POST #create' do
|
||||||
it 'opens the CFP of the specified conference' do
|
it 'opens the CFP of the specified conference' do
|
||||||
expect do
|
expect do
|
||||||
post 'create', conference_id: conference.id, format: :js
|
post 'create', current_conference: conference.slug, format: :js
|
||||||
end.to change { Conference.find(conference.id).call_for_participation.in_progress? }.from(false).to(true)
|
end.to change { Conference.find(conference.id).call_for_participation.in_progress? }.from(false).to(true)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -18,7 +18,7 @@ RSpec.describe Management::CallForParticipationsController, type: :controller do
|
||||||
conference.call_for_participation.open!
|
conference.call_for_participation.open!
|
||||||
|
|
||||||
expect do
|
expect do
|
||||||
delete 'destroy', conference_id: conference.id, format: :js
|
delete 'destroy', current_conference: conference.slug, format: :js
|
||||||
end.to change { Conference.find(conference.id).call_for_participation.in_progress? }.from(true).to(false)
|
end.to change { Conference.find(conference.id).call_for_participation.in_progress? }.from(true).to(false)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
FactoryGirl.define do
|
FactoryGirl.define do
|
||||||
factory :conference do
|
factory :conference do
|
||||||
title { |n| "Conference-#{n}" }
|
sequence(:title) { |n| "Conference-#{n}" }
|
||||||
email
|
email
|
||||||
description 'MyText'
|
description 'MyText'
|
||||||
start_date '2014-07-29 21:29:13'
|
start_date '2014-07-29 21:29:13'
|
||||||
|
|
Loading…
Reference in New Issue