Giter VIP home page Giter VIP logo

Comments (4)

wesleyeewong avatar wesleyeewong commented on July 26, 2024

Hey @koki-sato what would be a use-case for such behavior?

Is it just for instantiation and before persisting?

from array_enum.

koki-sato avatar koki-sato commented on July 26, 2024

Is it just for instantiation and before persisting?

Yes!

I expect the following behavior.

class User < ActiveRecord::Base
  extend ArrayEnum

  array_enum favourite_colors: {"red" => 1, "blue" => 2, "green" => 3}

  validates :favourite_colors, subset: { in: favourite_colors.keys }
end

user = User.new(favourite_colors: [""]) # Do not raise ArgumentError!
user.save # => false
user.errors.messages[:favourite_colors] # Display inclusion validation error message

For example, when the following data is HTTP POSTed in an HTML Form

user[favourite_colors][]: 

Rails Parameters look like this:

Parameters: { "user" => { "favourite_colors" => [""] } }

from array_enum.

wesleyeewong avatar wesleyeewong commented on July 26, 2024

@koki-sato I'll have a look into it, tho can't give a timeline right now. But if you already have some idea on how it'll work, feel free to create a PR and I'll review it.

from array_enum.

Related Issues (3)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.