fix controller update

This commit is contained in:
Stella 2014-12-09 21:40:34 +02:00
parent ecfc348ea8
commit 11d0a71231
4 changed files with 56 additions and 39 deletions

View file

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

View file

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

View file

@ -23,8 +23,11 @@
<b class="caret"></b>
%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 @@
<b class="caret"></b>
%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 @@
<b class="caret"></b>
%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

View file

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