Skip to content

Instantly share code, notes, and snippets.

View pduersteler's full-sized avatar

Pascal Dürsteler pduersteler

View GitHub Profile
@pduersteler
pduersteler / ModelController.php
Last active October 28, 2021 10:28
Extbase Multistep form example. Not finished, not perfect.
<?php
namespace Foo\Bar\Controller;
class ModelController extends \TYPO3\CMS\Extbase\Mvc\Controller\ActionController {
/**
* New action.
*
* Displays form in its current step.
*
* @param \Foo\Bar\Domain\Model\Model $model
[{"tid":24,"action":"Commands","method":"moveNodeAfterDestination","type":"rpc","result":{"serializeClassName":"TYPO3\\CMS\\Backend\\Tree\\Pagetree\\PagetreeNode","id":"p23","type":"pages","editableText":"Test","text":"Test","cls":null,"prefix":"","suffix":"","qtip":"id=35
Verborgen","expanded":true,"expandable":false,"draggable":true,"isTarget":true,"spriteIconCode":" <\/span><\/span>","t3TextSourceField":"title","t3InCopyMode":false,"t3InCutMode":false,"t3ContextInfo":[],"editable":true,"allowChildren":true,"nodeData":{"serializeClassName":"TYPO3\\CMS\\Backend\\Tree\\Pagetree\\PagetreeNode","id":"35","type":"pages","editableText":"Test","text":"Test","cls":null,"prefix":"","suffix":"","qtip":"id=35
Verborgen","expanded":true,"expandable":false,"draggable":true,"isTarget":true,"spriteIconCode":" <\/span><\/span>","t3TextSourceField":"title","t3InCopyMode":false,"t3InCutMode":false,"t3ContextInfo":[],"editable":true,"allowChildren":true,"readableRootline":"","mountPoint":0,"workspaceId":35,"isMountPoint":fals
class EnrollmentController < ApplicationController
def new
@users_assignments = []
3.times{ @users_assignments << @event.assignments.build }
end
end
# Aim: load all activities having the same customer.
#
# PublicActivity::Activity(id: integer, trackable_id: integer, trackable_type: string, ...)
# => belongs_to :trackable, polymorphic: true
# => trackable is either Project or Service
PublicActivity::Activity.joins(:trackable)
# ActiveRecord::EagerLoadPolymorphicError: Can not eagerly load the polymorphic association :trackable
class CredentialsController < ApplicationController
before_filter :assign_encryption_key
before_filter :request_encryption_key, unless: "Credential.key_present?", except: [:set_encryption_key]
def new
@credential = Credential.new
end
def create
module MyGem
module MyClassExtension
extend ActiveSupport::Concern
module ClassMethods
def does_something_to(modifiers = {}, *args)
cattr_accessor :my_gem_modifiers
self.my_gem_modifiers = modifiers
end
end
# in app/controllers/application_controller.rb
require 'thing/exceptions'
class ApplicationController < ActionController::Base
end
# app/controllers/application_controller.rb
class ApplicationController < ActionController::Base
require 'myapp/exceptions'
include MyApp::Exceptions
end
# config/application.rb
module Myapp
class Application < Rails::Application
<header_images>
<TCEforms type="array">
<config type="array">
<type>group</type>
<internal_type>file</internal_type>
<allowed>gif,png,jpg,jpeg</allowed>
<max_size>1000</max_size>
<uploadfolder>uploads/media</uploadfolder>
<show_thumbs>5</show_thumbs>
<size>5</size>
resources :recordings do
get '/:year/:month/:day', :on => :collection, :action => :index, :constraints => {:day => /\D{1,2}/, :month => /\D{1,2}/, :year => /\D{4}/}
end
<%= link_to 'previous day', recordings_path(:year => (@date-1.day).year, :month => (@date-1.day).month, :day => (@date-1.day).day) %>
# generates <a href="/recordings?year=yyy&month=mm&day=dd">
# desired: <a href="/recordings/yyyy/mm/dd"></a>