Skip to content

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

Open

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

Activity

  1. richmolj commented on Jun 5, 2018

    @richmolj
    Contributor

    Hey @hidde-jan! So this would be functionally equivalent but syntactic sugar, right? And protected/private methods.

    Not opposed to it if you'd like to PR!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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