1. 24 1月, 2014 1 次提交
  2. 21 1月, 2014 2 次提交
  3. 14 1月, 2014 1 次提交
  4. 11 1月, 2014 1 次提交
    • Y
      use enum labels as form values. Achieved by `_before_type_cast`. · 792c66f8
      Yves Senn 提交于
      Closes #13650, #13672
      
      This is an alternate implementation to solve #13650. Currently form fields
      contain the enum value (eg. "1"). This breaks because the setter `enum=`
      expects the label (eg. "active").
      
      ActiveRecord::Enum allows you to use labels in your application but store numbers.
      We should make sure that all parts after AR are dealing with labels and not the
      underlying mapping to a number.
      
      This patch defines `_before_type_cast` on every enum column to return the label.
      This method is later used to fetch the value to display in form fields.
      
      I deliberately copied the implementation of the enum getter instead of delegating to it.
      This allows you to overwrite the getter and for example return a `Value Object` but have it
      still work for form fields.
      792c66f8
  5. 04 1月, 2014 1 次提交
    • G
      Building new records with enum scopes now works as expected · 788bb40e
      Godfrey Chan 提交于
      Previously, this would give an `ArgumentError`:
      
         class Issue < ActiveRecord::Base
           enum :status, [:open, :finished]
         end
      
         Issue.open.build # => ArgumentError: '0' is not a valid status
         Issue.open.create # => ArgumentError: '0' is not a valid status
      
      PR #13542 muted the error, but the issue remains. This commit fixes
      the issue by allowing the enum value to be written directly via the
      setter:
      
         Issue.new.status = 0 # This now sets status to :open
      
      Assigning a value directly via the setter like this is not part of the
      documented public API, so users should not rely on this behavior.
      
      Closes #13530.
      788bb40e
  6. 02 1月, 2014 1 次提交
    • R
      Fix the enums writer methods · 7aebcb67
      Robin Dupret 提交于
      Previously, the writer methods would simply check whether the passed
      argument was the symbol representing the integer value of an enum field.
      Therefore, it was not possible to specify the numeric value itself but
      the dynamically defined scopes generate where clauses relying on this
      kind of values so a chained call to a method like `find_or_initialize_by`
      would trigger an `ArgumentError`.
      
      Reference #13530
      7aebcb67
  7. 01 1月, 2014 1 次提交
  8. 06 11月, 2013 3 次提交
  9. 05 11月, 2013 3 次提交
  10. 03 11月, 2013 5 次提交