Sha256: 092cd25a3348ab542ca1f4d77876399103a7e17d1890ac286bd0259535a3e7f9

Contents?: true

Size: 1.74 KB

Versions: 16

Compression:

Stored size: 1.74 KB

Contents

module Refinery
  module <%= class_name.pluralize %>
    class <%= class_name.pluralize %>Controller < ::ApplicationController

      before_filter :find_page, :only => [:create, :new]

      def index
        redirect_to :action => "new"
      end

      def thank_you
        @page = Refinery::Page.find_by_link_url("/<%= plural_name %>/thank_you", :include => [:parts])
      end

      def new
        @<%= singular_name %> = <%= class_name %>.new
      end

      def create
        @<%= singular_name %> = <%= class_name %>.new(params[:<%= singular_name %>])

        if @<%= singular_name %>.save
          begin
            Mailer.notification(@<%= singular_name %>, request).deliver
          rescue => e
            logger.warn "There was an error delivering the <%= singular_name %> notification.\n#{e.message}\n"
          end<% if @includes_spam %> if @<%= singular_name %>.ham?<% end %>

          if <%= class_name %>.column_names.map(&:to_s).include?('email')
            begin
              Mailer.confirmation(@<%= singular_name %>, request).deliver
            rescue => e
              logger.warn "There was an error delivering the <%= singular_name %> confirmation:\n#{e.message}\n"
            end<% if @includes_spam %> if @<%= singular_name %>.ham?<% end %>
          else
            logger.warn "Please add an 'email' field to <%= class_name %> if you wish to send confirmation emails when forms are submitted."
          end

          redirect_to refinery.thank_you_<%= namespacing.underscore %>_<%= plural_name %>_path
        else
          render :action => 'new'
        end
      end

    protected

      def find_page
        @page = Refinery::Page.find_by_link_url('/<%= plural_name %>/new', :include => [:parts])
      end

    end
  end
end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
refinerycms-core-2.1.5 lib/generators/refinery/form/templates/app/controllers/refinery/namespace/plural_name_controller.rb.erb
refinerycms-core-2.1.4 lib/generators/refinery/form/templates/app/controllers/refinery/namespace/plural_name_controller.rb.erb
refinerycms-core-2.1.3 lib/generators/refinery/form/templates/app/controllers/refinery/namespace/plural_name_controller.rb.erb
refinerycms-core-2.1.2 lib/generators/refinery/form/templates/app/controllers/refinery/namespace/plural_name_controller.rb.erb
refinerycms-core-2.1.1 lib/generators/refinery/form/templates/app/controllers/refinery/namespace/plural_name_controller.rb.erb
refinerycms-core-2.1.0 lib/generators/refinery/form/templates/app/controllers/refinery/namespace/plural_name_controller.rb.erb
refinerycms-core-2.0.10 lib/generators/refinery/form/templates/app/controllers/refinery/namespace/plural_name_controller.rb.erb
refinerycms-core-2.0.9 lib/generators/refinery/form/templates/app/controllers/refinery/namespace/plural_name_controller.rb.erb
refinerycms-core-2.0.8 lib/generators/refinery/form/templates/app/controllers/refinery/namespace/plural_name_controller.rb.erb
refinerycms-core-2.0.7 lib/generators/refinery/form/templates/app/controllers/refinery/namespace/plural_name_controller.rb.erb
refinerycms-core-2.0.6 lib/generators/refinery/form/templates/app/controllers/refinery/namespace/plural_name_controller.rb.erb
refinerycms-core-2.0.5 lib/generators/refinery/form/templates/app/controllers/refinery/namespace/plural_name_controller.rb
refinerycms-core-2.0.4 lib/generators/refinery/form/templates/app/controllers/refinery/namespace/plural_name_controller.rb
refinerycms-core-2.0.3 lib/generators/refinery/form/templates/app/controllers/refinery/namespace/plural_name_controller.rb
refinerycms-core-2.0.2 lib/generators/refinery/form/templates/app/controllers/refinery/namespace/plural_name_controller.rb
refinerycms-core-2.0.1 lib/generators/refinery/form/templates/app/controllers/refinery/namespace/plural_name_controller.rb