Fix cfp create and error display

This commit is contained in:
Stella 2014-05-04 13:09:49 +03:00
parent 4e395a0d7a
commit e3d21de1cb
4 changed files with 23 additions and 13 deletions

View file

@ -5,28 +5,38 @@ class Admin::CallforpapersController < ApplicationController
@cfp = @conference.call_for_papers
if @cfp.nil?
@cfp = CallForPapers.new
@url = admin_conference_callforpapers_path(@conference.short_title)
else
@url = admin_conference_callforpaper_path(@conference.short_title, @cfp)
end
end
def update
@cfp = @conference.call_for_papers
@cfp.update_attributes(params[:call_for_papers])
redirect_to(admin_conference_callforpapers_path(
id: @conference.short_title),
notice: 'Call for Papers was successfully updated.')
if @cfp.update_attributes(params[:call_for_papers])
redirect_to(admin_conference_callforpapers_path(
@conference.short_title),
notice: 'Call for Papers was successfully updated.')
else
flash.now[:error] = 'Call for Papers update failed. ' + @cfp.errors.full_messages.map {|e| e.humanize + "."}.join(" ")
@url = admin_conference_callforpaper_path(@conference.short_title, @cfp)
render action: "index"
end
end
def create
@cfp = CallForPapers.new(params[:call_for_papers])
@conference.call_for_papers = @cfp
@cfp.conference_id = @conference.id
if @cfp.save
redirect_to(admin_conference_callforpapers_path(
id: @conference.short_title),
notice: 'Call for Papers was successfully updated.')
@conference.short_title),
notice: 'Call for Papers was successfully created.')
else
redirect_to(admin_conference_callforpapers_path(
id: @conference.short_title),
error: 'Call for Papers failed.')
flash.now[:error] = 'Call for Papers creation failed. ' + @cfp.errors.full_messages.map {|e| e.humanize + "."}.join(" ")
@url = admin_conference_callforpapers_path(@conference.short_title)
render action: "index"
end
end
end

View file

@ -2,7 +2,7 @@ class CallForPapers < ActiveRecord::Base
attr_accessible :start_date, :end_date, :hard_deadline, :description, :schedule_changes, :rating, :rating_desc, :schedule_public
belongs_to :conference
validates_presence_of :start_date, :end_date, :hard_deadline
validates_presence_of :start_date, :end_date, :hard_deadline, :description
validates :rating, :numericality => { :greater_than_or_equal_to => 0, :less_than_or_equal_to => 10 }
end

View file

@ -2,7 +2,7 @@
.col-md-3
= render 'admin/conference/sidebar'
.col-md-9
= semantic_form_for(@cfp, :url => admin_conference_callforpaper_path(@conference.short_title, @conference.call_for_papers),:html => {:multipart => true}) do |f|
= semantic_form_for(@cfp, url: @url,:html => {:multipart => true}) do |f|
= f.input :start_date, :as => :string, :input_html => { :id => "conference-start-datepicker", :readonly => "readonly" }
= f.input :end_date, :as => :string, :input_html => { :id => "conference-end-datepicker", :readonly => "readonly" }
= f.input :hard_deadline, :as => :string, :input_html => { :id => "cfp-hard-datepicker", :readonly => "readonly" }

View file

@ -31,7 +31,7 @@ Osem::Application.routes.draw do
resources :social_events, only: [:show, :update, :index]
resources :supporter_levels, only: [:show, :update, :index]
resources :emails, only: [:show, :update, :index]
resources :callforpapers, only: [:show, :update, :index]
resources :callforpapers, only: [:create, :update, :index]
put "/questions/update_conference" => "questions#update_conference"
resources :questions
resources :events do