Sha256: 122b427a68823c2287a62fb6f3583449780d102dca4d2386809dff6996737a94

Contents?: true

Size: 1.66 KB

Versions: 1

Compression:

Stored size: 1.66 KB

Contents

class ClarkKent::UserReportEmailsController < ClarkKent::ApplicationController
  before_filter :prepare_user_report_email
  before_filter :prepare_report_email

  def new
    @user_report_email = ClarkKent::UserReportEmail.new(report_email_id: @report_email.id)
    render partial: 'form', locals: {user_report_email: @user_report_email}
  end

  def create
    @user_report_email = ClarkKent::UserReportEmail.new(params[:user_report_email])
    if @user_report_email.save
      render partial: 'show_wrapper', locals: {user_report_email: @user_report_email}
    else
      render partial: 'form', locals: {user_report_email: @user_report_email}, status: 409
    end
  end

  def show
    render partial: 'show', locals: {user_report_email: @user_report_email}
  end

  def edit
    render partial: 'form', locals: {user_report_email: @user_report_email}
  end

  def update
    @user_report_email.update_attributes(params[:user_report_email])
    @ajax_flash = {notice: "Your changes were saved."}
    render partial: 'show', locals: {user_report_email: @user_report_email}
  end

  def destroy
    @user_report_email.destroy
    render nothing: true
  end

  def prepare_user_report_email
    @user_report_email = ClarkKent::UserReportEmail.find(params[:id]) if params[:id]
  end

  def prepare_report_email
    report_email_id = params[:report_email_id]
    report_email_id ||= params[:user_report_email][:report_email_id] if params[:user_report_email]
    @report_email = ClarkKent::ReportEmail.find(report_email_id) if report_email_id
    @report_email ||= @user_report_email.report_email if @user_report_email
  end

  protected
  def authorize_user!
    authorize! :manage, :reports
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
clark_kent-0.0.1 app/controllers/clark_kent/user_report_emails_controller.rb