Sha256: 552b7de65179f3ea540dfbd78d17db5f0a9c6ac143870af27050b852ab886514

Contents?: true

Size: 1.45 KB

Versions: 23

Compression:

Stored size: 1.45 KB

Contents

module Ruhl
  module Rails
    module ActiveRecord
      def error_messages?
        !presentee.errors.empty?
      end
  
      def error_messages
        return if presentee.errors.empty?
        presentee.errors.full_messages
      end
  
      def define_paths(model)
        define_action(model, 'show')                      # show_path(@user)
        define_action(model, 'update')                    # update_path(@user)
        define_action(model, 'delete')                    # delete_path(@user)
        define_action("edit_#{model}", 'edit')            # edit_path(@user)
        define_action(model.pluralize, 'index', false)    # index_path
        define_action(model.pluralize, 'create', false)   # create_path
        define_action("new_#{model}", 'new', false)       # new_path
      end
  
      private
  
      def define_action(model, action, use_presentee = true)
        if use_presentee
          self.class.send(:define_method, "#{action}_path") do
            context.send("#{model}_path", presentee)
          end      
          self.class.send(:define_method, "#{action}_url") do
            context.send("#{model}_url", presentee)
          end      
        else
          self.class.send(:define_method, "#{action}_path") do
            context.send("#{model}_path")
          end      
          self.class.send(:define_method, "#{action}_url") do
            context.send("#{model}_url")
          end      
        end
      end
    end
  end
end

Version data entries

23 entries across 23 versions & 1 rubygems

Version Path
ruhl-1.3.6 lib/ruhl/rails/active_record.rb
ruhl-1.3.5 lib/ruhl/rails/active_record.rb
ruhl-1.3.4 lib/ruhl/rails/active_record.rb
ruhl-1.3.3 lib/ruhl/rails/active_record.rb
ruhl-1.3.2 lib/ruhl/rails/active_record.rb
ruhl-1.3.1 lib/ruhl/rails/active_record.rb
ruhl-1.3.0 lib/ruhl/rails/active_record.rb
ruhl-1.2.0 lib/ruhl/rails/active_record.rb
ruhl-1.1.1 lib/ruhl/rails/active_record.rb
ruhl-1.1.0 lib/ruhl/rails/active_record.rb
ruhl-1.0.0 lib/ruhl/rails/active_record.rb
ruhl-0.26.1 lib/ruhl/rails/active_record.rb
ruhl-0.26.0 lib/ruhl/rails/active_record.rb
ruhl-0.25.0 lib/ruhl/rails/active_record.rb
ruhl-0.24.0 lib/ruhl/rails/active_record.rb
ruhl-0.23.0 lib/ruhl/rails/active_record.rb
ruhl-0.22.0 lib/ruhl/rails/active_record.rb
ruhl-0.21.0 lib/ruhl/rails/active_record.rb
ruhl-0.20.0 lib/ruhl/rails/active_record.rb
ruhl-0.19.0 lib/ruhl/rails/active_record.rb