From 11d0a71231e4964658cceac31e0b8d9ce7fab639 Mon Sep 17 00:00:00 2001 From: Stella Date: Tue, 9 Dec 2014 21:40:34 +0200 Subject: [PATCH] fix controller update --- app/controllers/admin/events_controller.rb | 35 ++++++++-------------- app/models/event.rb | 6 ++-- app/views/admin/events/_proposal.html.haml | 24 ++++++++++----- app/views/admin/events/index.html.haml | 30 +++++++++++++++---- 4 files changed, 56 insertions(+), 39 deletions(-) diff --git a/app/controllers/admin/events_controller.rb b/app/controllers/admin/events_controller.rb index 9da0ae7e..0747dfae 100644 --- a/app/controllers/admin/events_controller.rb +++ b/app/controllers/admin/events_controller.rb @@ -18,6 +18,7 @@ module Admin @conference = Conference.find_by(short_title: params[:conference_id]) @events = @conference.events @tracks = @conference.tracks + @difficulty_levels = @conference.difficulty_levels @machine_states = @events.state_machine.states.map @event_types = @conference.event_types @@ -104,27 +105,15 @@ module Admin end def update - if params.has_key? :track_id - @event.update_attribute(:track_id, params[:track_id]) - end - if params.has_key? :event_type_id - @event.update_attribute(:event_type_id, params[:event_type_id]) - end - if params.has_key? :difficulty_level_id - @event.update_attribute(:difficulty_level_id, params[:difficulty_level_id]) - end - if params.has_key? :is_highlight - @event.update_attribute(:is_highlight, params[:is_highlight]) - end - - if @event.submitter.update_attributes!(params[:user]) && @event. - update_attributes!(params[:event]) - flash[:notice] = "Successfully updated #{@event.title}." + if @event.submitter.update_attributes(params[:user]) && + @event.update_attributes(params[:event]) + flash[:notice] = "Successfully updated event with ID #{@event.id}." + redirect_back_or_to(admin_conference_event_path(@conference.short_title, @event)) else - flash[:notice] = 'Update not successful.' + @url = admin_conference_event_path(@conference.short_title, @event) + flash[:notice] = 'Update not successful. ' + @event.errors.full_messages.to_sentence + render :edit end - - redirect_back_or_to(admin_conference_event_path(@conference.short_title, @event)) end def create; end @@ -186,11 +175,11 @@ module Admin alert = @event.update_state(transition, mail, subject, send_mail, params[:send_mail].blank?) if !alert.blank? - return redirect_to(admin_conference_events_path(conference_id: @conference.short_title), - alert: alert) && return + flash[:error] = error + return redirect_back_or_to(admin_conference_events_path(conference_id: @conference.short_title)) && return else - redirect_to(admin_conference_events_path(conference_id: @conference.short_title), - notice: notice) && return + flash[:notice] = notice + redirect_back_or_to(admin_conference_events_path(conference_id: @conference.short_title)) && return end end end diff --git a/app/models/event.rb b/app/models/event.rb index 81b4103e..47206b94 100644 --- a/app/models/event.rb +++ b/app/models/event.rb @@ -1,9 +1,9 @@ class Event < ActiveRecord::Base include ActiveRecord::Transitions has_paper_trail - attr_accessible :title, :subtitle, :abstract, :description, :event_type_id, :users_attributes, - :user, :proposal_additional_speakers, :track_id, - :require_registration, :difficulty_level_id + attr_accessible :title, :subtitle, :abstract, :description, :user, :users_attributes, + :proposal_additional_speakers, :event_type_id, :track_id, + :difficulty_level_id, :require_registration, :is_highlight acts_as_commentable diff --git a/app/views/admin/events/_proposal.html.haml b/app/views/admin/events/_proposal.html.haml index fdf17ba7..1d3b6398 100644 --- a/app/views/admin/events/_proposal.html.haml +++ b/app/views/admin/events/_proposal.html.haml @@ -23,8 +23,11 @@ %ul.dropdown-menu - @event_types.each do |type| - %li= link_to type.title, admin_conference_event_path(@conference.short_title, @event, :event_type_id => type.id) , - :method => :put, :event_type_id => type.id + %li= link_to type.title, + admin_conference_event_path(@conference.short_title, + @event, + event: { event_type_id: type.id }), + method: :patch %tr %td %b Highlight @@ -32,8 +35,8 @@ = link_to "#{@event.is_highlight}".capitalize, admin_conference_event_path(@conference.short_title, @event, - is_highlight: !@event.is_highlight), - method: :put, is_highlight: !@event.is_highlight + event: { is_highlight: !@event.is_highlight }), + method: :patch - if @event.is_highlight (the event is as a highlight and will appear in the splashpage) - else @@ -61,8 +64,11 @@ %ul.dropdown-menu - @tracks.each do |track| - %li= link_to track.name, admin_conference_event_path(@conference.short_title, @event, :track_id => track.id) , - :method => :put, :track_id => track.id + %li= link_to track.name, + admin_conference_event_path(@conference.short_title, + @event, + event: { track_id: track.id }), + method: :patch %tr %td %b Difficulty @@ -76,8 +82,10 @@ %ul.dropdown-menu - @difficulty_levels.each do |difficulty| - %li= link_to difficulty.title, admin_conference_event_path(@conference.short_title, @event, :difficulty_level_id => difficulty.id) , - :method => :put, :difficulty_level_id => difficulty.id + %li= link_to difficulty.title, admin_conference_event_path(@conference.short_title, + @event, + event: { difficulty_level_id: difficulty.id }), + method: :patch - if !@event.room.nil? %tr %td diff --git a/app/views/admin/events/index.html.haml b/app/views/admin/events/index.html.haml index 3dd123e1..ab300d0e 100644 --- a/app/views/admin/events/index.html.haml +++ b/app/views/admin/events/index.html.haml @@ -80,8 +80,11 @@ %span.caret %ul.dropdown-menu - @event_types.each do |type| - %li= link_to type.title, admin_conference_event_path(@conference.short_title, event, :event_type_id => type.id) , - :method => :put, :event_type_id => type.id + %li= link_to type.title, + admin_conference_event_path(@conference.short_title, + event, + event: { event_type_id: type.id }), + method: :patch %td .btn-group %button{:type=>"button", :class=>"btn btn-link dropdown-toggle", "data-toggle"=>"dropdown"} @@ -92,10 +95,27 @@ %span.caret %ul.dropdown-menu - @tracks.each do |track| - %li= link_to track.name, admin_conference_event_path(@conference.short_title, event, :track_id => track.id) , - :method => :put, :track_id => track.id + %li= link_to track.name, + admin_conference_event_path(@conference.short_title, + event, + event: { track_id: track.id }), + method: :patch %td - = event.difficulty_level.title if event.difficulty_level + .btn-group + %button{:type=>"button", :class=>"btn btn-link dropdown-toggle", "data-toggle"=>"dropdown"} + - if event.difficulty_level.nil? + Difficulty + - else + = event.difficulty_level.title + %span.caret + %ul.dropdown-menu + - @difficulty_levels.each do |difficulty_level| + %li= link_to difficulty_level.title, + admin_conference_event_path(@conference.short_title, + event, + event: { difficulty_level_id: difficulty_level.id }), + method: :patch + %td - if event.state == "withdrawn" Withdrawn