Skip to content

Allow opts[:if] to be a symbol #9

@hidde-jan

Description

@hidde-jan

Currently, you can pass an :if option to the attribute directive. It would be helpful if this option could be a symbol of a method on the controller instead of a Proc. It would function like before_action on controllers and validate on models. Instead of passing the current controller/context into the proc, you'd just call the method on the controller (or maybe call it from 'within' the context of the controller so it can use private/protected methods, similar to before_action).

Example:

# config/initializers/strong_resources.rb
strong_resource :person do
  attribute :age, :integer, if: :admin?
end

class PeopleController < ApplicationController
  strong_resource :person

  def admin?
    current_user.admin?
  end
end

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions