Sha256: 82343ef6c30e64dfa0470a38f32b9113e9066548c2a614a2fb45ccc2175e27d2

Contents?: true

Size: 1.14 KB

Versions: 5

Compression:

Stored size: 1.14 KB

Contents

class DailyReportsController < InheritedResources::Base
  nested_belongs_to :daily_table, :optional => true
  filter_resource_access :nested_in => :daily_table, :additional_member => :generate
  
  def create
    build_resource.user = current_user
    create! do |success, failure|
      success.all { redirect_to daily_table_daily_report_path(@daily_report.table, @daily_report)}
      failure.all { render :new }
    end
  end
  
  def update
    update! do |success, failure|
      success.all { redirect_to daily_table_daily_report_path(@daily_report.table, @daily_report)}
      failure.all { render :edit }
    end
  end
  
  def generate
    @daily_report.queue_now!
    redirect_to daily_table_daily_report_path(@daily_report.table, @daily_report)
  end
  
  protected
  
  # methods to make declarative_authorization allow optional table
  def load_daily_table
    @daily_table ||= load_parent_controller_object(:daily_table) if params[:daily_table_id]
    @daily_table  # loaded by inherited_resources if there
  end
  def new_daily_report_for_collection
    @daily_report ||= @daily_table ? new_controller_object_for_collection : DailyReport.new
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
daily-0.0.8 app/controllers/daily_reports_controller.rb
daily-0.0.7 app/controllers/daily_reports_controller.rb
daily-0.0.6 app/controllers/daily_reports_controller.rb
daily-0.0.5 app/controllers/daily_reports_controller.rb
daily-0.0.4 app/controllers/daily_reports_controller.rb