Technical Documentation
Return to Main Documentation
ENGLISH - version 2.3
ENGLISH - version 2.3
  • Introduction
  • Getting started
    • Create your fork
    • Configure your fork
    • Keep your fork updated
    • Communication
  • Installation
    • Local installation
      • Prerequisites
      • Ubuntu Linux
      • Debian Linux
      • macOS
      • Windows
      • Vagrant
      • Docker
    • Production and staging servers
      • Installer
      • Create a deploy user
      • Generating SSH Key
      • Manual installation (not recommended)
      • Digital Ocean
      • Heroku
      • Mail server configuration
    • Basic configuration
    • User documentation and guides
  • Customization
    • Introduction
    • Translations and texts
    • Images
    • Styles with CSS
    • JavaScript
    • Models
    • Controllers
    • Views and HTML
    • Components
    • Other Ruby classes (GraphQL, lib, mailers, builders)
    • Gems
    • Application configuration
    • Routes
    • Tests
  • Technical Features
    • OAuth
    • GraphQL
    • Debates and proposals recommendations
    • Configure Census Connection
    • Local Census
    • Multitenancy
    • User content translations
  • Open Source project
    • Code of conduct
    • Contributing
    • Coding conventions
    • Open source forks and modifications
    • License
Powered by GitBook
On this page
  1. Customization

Controllers

PreviousModelsNextViews and HTML

Last updated 2 months ago

Just like models, controllers are written using Ruby code, so their customization is similar, only we'll use the app/controllers/custom/ folder instead of the app/models/custom/ folder. Check the section for more information.

Customizing allowed parameters

When customizing Consul Democracy, sometimes you might want to add a new field to a form. Other than or that renders that form, you need to modify the controller so the new field is accepted. If not, the new field will silently be ignored; this is done to prevent .

For example, let's say you've modified the SiteCustomization::Page model so it uses a field called author_nickname and you've added that field to the form to create a custom page in the admin area. To add the allowed parameter to the controller, create a file app/controllers/custom/admin/site_customization/pages_controller.rb with the following content:

load Rails.root.join("app", "controllers", "admin", "site_customization", "pages_controller.rb")

class Admin::SiteCustomization::PagesController

  private

    alias_method :consul_allowed_params, :allowed_params

    def allowed_params
      consul_allowed_params + [:author_nickname]
    end
end

Note we're aliasing and then calling the original allowed_params method, so all the parameters allowed in the original code will also be allowed in our custom method.

models customization
customizing the view
the component
mass assignment attacks