Sha256: 6174caa40d0cfcebe99c9e7285af20cba9264816667f085255200d3cb221db08

Contents?: true

Size: 1.47 KB

Versions: 7

Compression:

Stored size: 1.47 KB

Contents

class SchoolsController < ApplicationController

  ssl_exceptions
  authorize_resource
  
  def index
    @selected_school = params[:new_school_id] ? School.where("id = ?", params[:new_school_id]).first : nil
    @schools = School.learner_form_search(params[:zipcode], @selected_school)

    render_success
  end

  def create
    @school = School.new params[:school]

    @school.approved = current_user && current_user.is_admin?

    if @school && @school.save
      render :json => @school.to_client_model_json
    else
      render_error
    end
  end
  
  def update
    @school = School.where("id = ?", params[:id]).first

    if @school && @school.update_attributes(params[:school])
      # @schools = School.learner_form_search(@school.zipcode, @school)
      # @selected_school = @school
      render :json => @school.to_client_model_json
      # render_success
    else
      render_error
    end
  end

  def edit
    @school = School.where("id = ?", params[:id]).first

    render :partial => 'form', :layout => false
  end

  private
  def render_success
    render :json => { 
        :status => :ok, 
        :html => render_to_string(:partial => 'search')
      }.to_json 
  end

  def render_error
    render :status => 400, :json => {
        :status => :error,
        :message => 'Your educational institution could not be saved. Please review the form and verify all required fields are completed',
        :html => render_to_string(:partial => 'form.html')
      }.to_json
  end

end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
scidea-schools-1.1 app/controllers/schools_controller.rb
scidea-schools-1.0.6 app/controllers/schools_controller.rb
scidea-schools-1.0.5 app/controllers/schools_controller.rb
scidea-schools-1.0.4 app/controllers/schools_controller.rb
scidea-schools-1.0.3 app/controllers/schools_controller.rb
scidea-schools-1.0.2 app/controllers/schools_controller.rb
scidea-schools-1.0.1 app/controllers/schools_controller.rb