---
title: "Use Pundit Policies to manage permitted parameters, defaults and per action"
description: "To manage permitted params you can add permitted\\attributes and permitted\\attributes\\for\\#{action} in your policies e.g."
canonical: https://oozou.com/til/use-pundit-policies-to-manage-permitted-parameters-defaults-and-per-action-188
locale: en
date: 2022-02-10
topic: ruby-on-rails
---

# Use Pundit Policies to manage permitted parameters, defaults and per action

> To manage permitted params you can add permitted\attributes and permitted\attributes\for\#{action} in your policies e.g.

Published: 2022-02-10 · Topic: [ruby on rails](https://oozou.com/til-topics/ruby-on-rails) ([markdown](https://oozou.com/til-topics/ruby-on-rails.md))

To manage permitted params you can add permitted\_attributes and permitted\_attributes\_for\_#\{action} in your policies e.g.

```ruby
class CommentPolicy < ApplicationPolicy
  def permitted_attributes
    %i[body]
  end

  def permitted_attributes_for_create
    %i[body application_id]
  end
end
```

Then in your controller

```ruby
class CommentController
  def create
    @comment = Comment.create(comment_attributes) # { body: 'body', application_id: 1 }
  end
 
  def update
    @comment = Comment.find(params[:id])
    @comment.update(comment_attributes) # { body: 'new body' }
  end
 
  private def comment_attributes
    permitted_attributes(Comment)
  end
end
```

---

Contact OOZOU: hello@oozou.com · +66 2544 0000 · https://oozou.com/contact

More for AI agents: https://oozou.com/llms.txt · every page has a markdown twin at its URL plus ".md"
