Put current conference in url

This commit is contained in:
Andrew Radev 2015-06-09 21:50:23 +03:00
parent 1bbebb54d3
commit fb7c39315a
3 changed files with 35 additions and 8 deletions

View File

@ -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

View File

@ -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

View File

@ -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