Sha256: 32f2837dac93f2d3c00ec1d28b44862b4a325f633bdf980d27251915da782024

Contents?: true

Size: 1.37 KB

Versions: 3

Compression:

Stored size: 1.37 KB

Contents

class <%= class_name %><%= step_alias.pluralize.camelize %>Controller < ApplicationController
  include <%= class_name %><%= step_alias.pluralize.camelize %>Helper
  helper <%= class_name %><%= step_alias.pluralize.camelize %>Helper
  before_action :load_<%= file_path %>

  def edit
    if <%= file_path %>_<%= step_alias %>_model.editable?
      if <%= step_alias %>.present?
        render <%= step_alias %>
      else
        render "#{Rails.root.to_s}/public/404.html", :layout => false, :status => 404
      end
    else
      redirect_to :back, :alert => I18n.t("<%= file_path %>.#{@<%= file_path %>.status}_editable_error")
    end
  end

  def update
    if <%= file_path %>_<%= step_alias %>_model.update_attributes(<%= file_path %>_params || {})
      if next_<%= step_alias %> && params[:commit].downcase.include?('next')
        redirect_to edit_<%= file_path %>_<%= file_path %>_<%= step_alias %>_path(<%= file_path %>_<%= step_alias %>_model, next_<%= step_alias %>)
      else
        redirect_to <%= file_path %>_path(@<%= file_path %>)
      end
    else
      render <%= step_alias %>, :error => "Please complete all required fields"
    end
  end

  private

  def load_<%= file_path %>
    @<%= file_path %> = <%= file_path %>_<%= step_alias %>_model
  end

  def <%= file_path %>_params
    params.require(:<%= file_path %>).permit(<%= controller_attribute_names %>)
  end

end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
ultra_light_wizard-0.1.4 lib/generators/templates/app/controllers/wizard_steps_controller.rb.erb
ultra_light_wizard-0.1.3 lib/generators/templates/app/controllers/wizard_steps_controller.rb.erb
ultra_light_wizard-0.1.2 lib/generators/templates/app/controllers/wizard_steps_controller.rb.erb