Nest everything under /conferences/:id/ again

Would be more straightforward to work with, even if it's a bit more
verbose sometimes.
This commit is contained in:
Andrew Radev 2015-07-19 11:44:44 +03:00
parent 798ffd8a39
commit c6750d3a1a
15 changed files with 38 additions and 49 deletions

View File

@ -10,7 +10,7 @@ module Management
@conference = Conference.new(conference_params)
if @conference.save
redirect_to management_conference_path(@conference, current_conference: @conference.slug)
redirect_to [:management, @conference]
else
render :new
end

View File

@ -1,21 +1,23 @@
module Management
class EventsController < ManagementController
before_action :require_current_conference
def index
@conference = find_conference
# TODO (2015-07-14) Scoped by conference? Why no conference_id
@events = Event.all
end
def show
@conference = find_conference
@event = Event.find(params[:id])
end
def edit
@conference = find_conference
@event = Event.find(params[:id])
end
def update
@conference = find_conference
@event = Event.find(params[:id])
if @event.update_attributes(event_params)
@ -27,6 +29,7 @@ module Management
end
def destroy
@conference = find_conference
@event = Event.find(params[:id])
@event.destroy
@ -35,6 +38,10 @@ module Management
private
def find_conference
Conference.find(params[:conference_id])
end
def event_params
params.require(:event).permit(
:title,

View File

@ -2,10 +2,5 @@ module Management
class HomeController < ManagementController
def index
end
def set_conference
conference = Conference.find(params[:id])
redirect_to management_conference_path(conference, current_conference: conference.slug)
end
end
end

View File

@ -6,22 +6,17 @@ module Management
private
def default_url_options(options = {})
{ current_conference: current_conference.try(:slug) }.merge(options)
end
def current_conference?
current_conference.present?
end
helper_method :current_conference?
def current_conference
@current_conference ||=
begin
if params[:current_conference]
Conference.find_by_slug(params[:current_conference])
end
if not @current_conference and params[:conference_id].present?
@current_conference = Conference.find(params[:conference_id])
end
@current_conference
end
helper_method :current_conference

View File

@ -1,31 +1,31 @@
module ApplicationHelper
def action_buttons(record, actions = [:index, :show, :edit, :destroy])
def action_buttons(conference, record, actions = [:index, :show, :edit, :destroy])
klass = record.class
output = ''
if actions.include? :index
output += link_to(icon(:list), [:management, klass], {
output += link_to(icon(:list), [:management, conference, klass], {
title: t('actions.index.button', models: klass.model_name.human(count: 2)),
class: 'btn btn-info'
})
end
if actions.include? :show
output += link_to(icon(:eye), [:management, record], {
output += link_to(icon(:eye), [:management, conference, record], {
title: t('actions.view.button', model: klass.model_name.human),
class: 'btn btn-info'
})
end
if actions.include? :edit
output += link_to(icon(:edit), [:edit, :management, record], {
output += link_to(icon(:edit), [:edit, :management, conference, record], {
title: t('actions.edit.button', model: klass.model_name.human),
class: 'btn btn-primary'
})
end
if actions.include? :destroy
output += link_to(icon(:trash), [:management, record], {
output += link_to(icon(:trash), [:management, conference, record], {
method: :delete,
data: {confirm: t('actions.are_you_sure')},
title: t('actions.edit.button', model: klass.model_name.human),

View File

@ -16,7 +16,6 @@ class Conference < ActiveRecord::Base
accepts_nested_attributes_for :tracks, :halls, reject_if: :all_blank, allow_destroy: true
before_create :slugify_title
after_create :create_call_for_participation
def submissions_grouped_by_day
@ -29,14 +28,6 @@ class Conference < ActiveRecord::Base
submissions.group_by { |s| s.confirmed_at.to_date }
end
def self.find_by_slug(slug)
find_by(slug: slug)
end
def slugify_title
self.slug = title.gsub(/\s+/, '-')
end
private
def start_date_is_before_end_date

View File

@ -18,7 +18,7 @@ nav.navbar.navbar-static-top.navbar-inverse role="navigation"
= current_conference.title
li class="#{'active' if controller_name == 'events'}"
= link_to management_events_path do
= link_to [:management, current_conference, :events] do
=> icon 'file-text', Event.model_name.human(count: 2).mb_chars.capitalize, class: 'fa-fw'
li class="#{'active' if controller_name == 'sponsorship_offers'}"
= link_to '#' do

View File

@ -17,7 +17,7 @@
div
= t Event.model_name.human(count: @conference.events.count)
= link_to management_events_path
= link_to [:management, @conference, :events] do
.panel-footer.text-primary
span.pull-left = t 'views.conference.see_details'
span.pull-right = icon 'arrow-circle-right'
@ -34,7 +34,7 @@
= @conference.events.rejected.count
div
= t 'event_states.rejected', count: @conference.events.rejected.count
= link_to management_events_path(status: :rejected)
= link_to [:management, @conference, :events, {status: :rejected}]
.panel-footer.text-danger
span.pull-left = t 'views.conference.see_details'
span.pull-right = icon 'arrow-circle-right'
@ -51,7 +51,7 @@
= @conference.events.approved.count
div
= t 'event_states.approved', count: @conference.events.approved.count
= link_to management_events_path(status: :approved)
= link_to [:management, @conference, :events, {status: :approved}]
.panel-footer.text-info
span.pull-left = t 'views.conference.see_details'
span.pull-right = icon 'arrow-circle-right'
@ -67,7 +67,7 @@
= @conference.events.approved.confirmed.count
div
= t 'event_states.confirmed', count: @conference.events.approved.confirmed.count
= link_to management_events_path(status: :approved, confirmed: true)
= link_to [:management, @conference, :events, {status: :approved, confirmed: true}]
.panel-footer.text-success
span.pull-left = t 'views.conference.see_details'
span.pull-right = icon 'arrow-circle-right'

View File

@ -1,11 +1,11 @@
.row
.col-lg-12
= simple_nested_form_for [:management, @event], wrapper: :horizontal_form, html: { class: 'form-horizontal' } do |f|
= simple_nested_form_for [:management, @conference, @event], wrapper: :horizontal_form, html: { class: 'form-horizontal' } do |f|
.panel.panel-primary
.panel-heading
h1.panel-title
= t 'views.user.info'
= link_to icon(:eye), [:management, @event], class: 'btn btn-xs btn-info pull-right'
= link_to icon(:eye), [:management, @conference, @event], class: 'btn btn-xs btn-info pull-right'
.panel-body
.row

View File

@ -23,4 +23,4 @@
td.actions
div.btn-group.btn-group-sm
= action_buttons(event, [:show, :edit, :destroy])
= action_buttons(@conference, event, [:show, :edit, :destroy])

View File

@ -22,4 +22,4 @@
.panel-footer
div.btn-group.btn-group-sm
= action_buttons(@event, [:index, :edit, :destroy])
= action_buttons(@conference, @event, [:index, :edit, :destroy])

View File

@ -8,7 +8,7 @@
span.caret<
ul.dropdown-menu role="menu"
- Conference.all.each do |conference|
li= link_to conference.title, management_set_conference_path(conference), method: :put
li= link_to conference.title, [:management, conference]
= link_to new_management_conference_path, class: 'btn btn-lg btn-primary'
=> icon 'plus', t('actions.create.button', model: Conference.model_name.human), class: 'fa-fw'

View File

@ -4,11 +4,7 @@ Rails.application.routes.draw do
namespace :management do
root to: 'home#index'
put '/set_conference/:id', to: 'home#set_conference', as: :set_conference
resources :conferences
scope ':current_conference' do
resources :conferences do
resources :events
resources :volunteers
resources :sponsorship_offers

View File

@ -0,0 +1,5 @@
class RemoveSlugFromConferences < ActiveRecord::Migration
def change
remove_column :conferences, :slug
end
end

View File

@ -8,7 +8,7 @@ RSpec.describe Management::CallForParticipationsController, type: :controller do
describe 'POST #create' do
it 'opens the CFP of the specified conference' do
expect do
post 'create', current_conference: conference.slug, format: :js
post 'create', conference_id: conference.id, format: :js
end.to change { Conference.find(conference.id).call_for_participation.in_progress? }.from(false).to(true)
end
end
@ -18,7 +18,7 @@ RSpec.describe Management::CallForParticipationsController, type: :controller do
conference.call_for_participation.open!
expect do
delete 'destroy', current_conference: conference.slug, format: :js
delete 'destroy', conference_id: conference.id, format: :js
end.to change { Conference.find(conference.id).call_for_participation.in_progress? }.from(true).to(false)
end
end