From fb7c39315acfc5c93647302091f234bc3d0a9d25 Mon Sep 17 00:00:00 2001 From: Andrew Radev Date: Tue, 9 Jun 2015 21:50:23 +0300 Subject: [PATCH] Put current conference in url --- .../management/management_controller.rb | 16 +++++++++++++++- app/models/conference.rb | 10 ++++++++++ config/routes.rb | 17 ++++++++++------- 3 files changed, 35 insertions(+), 8 deletions(-) diff --git a/app/controllers/management/management_controller.rb b/app/controllers/management/management_controller.rb index 80f6bfa..3cbf159 100644 --- a/app/controllers/management/management_controller.rb +++ b/app/controllers/management/management_controller.rb @@ -6,13 +6,27 @@ module Management private + def default_url_options(options = {}) + { current_conference: current_conference.slug }.merge(options) + end + def current_conference? current_conference.present? end helper_method :current_conference? + # TODO (2015-06-09) Fetch conferences by slug only 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 + + if session[:current_conference_id] + Conference.find_by(id: session[:current_conference_id]) + end + end end helper_method :current_conference diff --git a/app/models/conference.rb b/app/models/conference.rb index af860bd..1f774a5 100644 --- a/app/models/conference.rb +++ b/app/models/conference.rb @@ -28,6 +28,16 @@ class Conference < ActiveRecord::Base submissions.group_by { |s| s.confirmed_at.to_date } end + def slug + title.gsub(' ', '-') + end + + # TODO (2015-06-09) Stupid and temporary, put slug in db + # TODO (2015-06-09) Also, doesn't work due to translations? + # def self.find_by_slug(slug) + # find_by(title: slug.to_s.gsub('-', ' ')) + # end + private def start_date_is_before_end_date diff --git a/config/routes.rb b/config/routes.rb index bd0152e..ae1d2a8 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -7,14 +7,17 @@ Rails.application.routes.draw do put '/set_conference/:id', to: 'home#set_conference', as: :set_conference resources :conferences - resources :events - resources :volunteers - resources :sponsorship_offers - resource :call_for_participation, only: [:create, :destroy] - resources :users do - member do - put :toggle_admin + scope ':current_conference' do + resources :events + resources :volunteers + resources :sponsorship_offers + resource :call_for_participation, only: [:create, :destroy] + + resources :users do + member do + put :toggle_admin + end end end end