Giter Site home page Giter Site logo

enum_help's Issues

The method .references() must contain arguments

I have a column called reference of type string. It is not related to enums. It works just fine when not using enum_help gem. But by just adding enum_help gem in Gemfile it gives The method .references() must contain arguments in this line of view:

<%= f.input :reference %>

Stack trace:

activerecord (4.1.2.rc1) lib/active_record/relation/query_methods.rb:1086:in `check_if_method_has_arguments!'
activerecord (4.1.2.rc1) lib/active_record/relation/query_methods.rb:182:in `references'
activerecord (4.1.2.rc1) lib/active_record/querying.rb:10:in `references'
enum_help (0.0.6) lib/enum_help/simple_form.rb:20:in `initialize'
simple_form (3.1.0.rc1) lib/simple_form/form_builder.rb:501:in `new'
simple_form (3.1.0.rc1) lib/simple_form/form_builder.rb:501:in `find_input'
simple_form (3.1.0.rc1) lib/simple_form/form_builder.rb:112:in `input'
app/views/products/_form.html.erb:5:in `block in _app_views_products__form_html_erb___1832036717949421423_70310092763500'

Capitalize the outputted choices?

Is there a way to capitalize the outputted choices from an enum? For instance, I have:

<%= f.input :status, as: :radio_buttons %>

This outputs the statuses that I have declared with an enum, but they are lowercase. I just want to capitalize the first letter of each choice.

Any way to do this?

i18n array with int keys

For sorting action need [["planed", 0], ["done", 1], ["loaded", 2]] with translated key.
But Model.statuses_i18n returns array with value = translated(key) and there is no integer keys to find something in database.
Maybe it's not so hard to make enums translated with integer keys?

"No" shown as "false"

When I have an enum option that is translated as "No", simple_form shows "false".
Am I wrong?

PS: workaround is adding a space after "No":

enums:
  user:
    product_already_have_km:
      already_customer: 'Sì'
      new_customerr: 'No '

Adding gem to Rails 5 project changes belongs_to behavior

I'm not sure what is causing this, but when this gem is added to a Rails 5 project, belongs_to associations are no longer required by default.

Current workaround is to add required: true to all belongs_to relationships where you want the Rails 5 default behavior.

Enum delegated attribute

Hello,

this gem works great!

One feature could be great, if it could work with delegated attribute. Eg. when is attribute with enum values delegated to another class simple_form doesn't show select box.

Translation for enums in model concerns

I use enum in model concern because of using it in multiple models:

module Sizeable
  extend ActiveSupport::Concern

  included do
    enum pizza_size: { d22: 22, d33: 33, d38: 38 }
  end
end

How should I write translations in .yml file? I can write duplicated translations for each model used concern, but this isn't DRY

display enum field value in view

thanks for such a great gem.
i have a question, is there a way to overwrite the default behavior in view level? Because sometimes I just want to display the actual value of the enum field in the HTML page. But currently if I do

<%=task.status%>

In the html file, I see following

{:pending => "Pending", :confirmed => "Confirm" ...} 

It will be great if I can just see its status.
Thanks

Select field not generated

If I use <%= f.input :status %> (as explained in the documentation) it generates a numeric input field instead of a select. To achieve the expected behavior I have to put = f.input :state, collection: Project.statuses_i18n, label_method: :last, value_method: :first. Is this a Bug or an error in the documentation?

input as radio buttons doesn't work

When I try to use this gem with simple form and try to show values as radio buttons it shows radio buttons with Yes, No labels (there are only two options in enum for now).

class Plan
  enum payout_period: [:monthly, :at_the_end]
end
= f.input :payout_period, as: :radio_buttons

simple from item_wrapper_tag and item_wrapper_class not working

Wrapper

 config.wrappers :vertical_inline_radio_and_checkboxes, tag: 'fieldset', class: 'form-group', error_class: 'has-danger', 
    item_wrapper_tag: :span, item_wrapper_class: "form-check-inline", item_label_class: 'form-check-label' do |b|
    b.use :html5
    b.optional :readonly
    b.use :label, class: 'form-control-label'
    b.wrapper tag: 'div', class: 'row' do |c|
      c.use :input, class: 'form-check-input'
    end
    b.use :error, wrap_with: { tag: 'span', class: 'form-control-feedback' }
    b.use :hint,  wrap_with: { tag: 'span', class: 'form-text text-muted' }
   
  end

expected result

<fieldset class="form-group radio_buttons required user_enrollment col-md-12">
    <label class="form-control-label radio_buttons required"><abbr title="required">*</abbr>Your are</label>
    <div class="row">
       <input type="hidden" name="user[enrollment]" value="">
       <span class="radio form-check-inline">
           <label class="form-check-label" for="user_enrollment_student">
               <input class="form-check-input radio_buttons required" type="radio" value="student" name="user[enrollment]" id="user_enrollment_student">
                Student
           </label>
       </span>
       <span class="radio form-check-inline">
          <label class="form-check-label" for="user_enrollment_lecturer">
              <input class="form-check-input radio_buttons required" type="radio" value="lecturer" name="user[enrollment]" id="user_enrollment_lecturer">
               Lecturer
           </label>
       </span>
    </div>
</fieldset>

result

<fieldset class="form-group radio_buttons required user_enrollment col-md-12">
    <label class="form-control-label radio_buttons required"><abbr title="required">*</abbr>Your are</label>
    <div class="row">
       <input type="hidden" name="user[enrollment]" value="">
       <span class="radio radio radio">
           <label class="form-check-label" for="user_enrollment_student">
               <input class="form-check-input radio_buttons required" type="radio" value="student" name="user[enrollment]" id="user_enrollment_student">
                Student
           </label>
       </span>
       <span class="radio radio radio">
          <label class="form-check-label" for="user_enrollment_lecturer">
              <input class="form-check-input radio_buttons required" type="radio" value="lecturer" name="user[enrollment]" id="user_enrollment_lecturer">
               Lecturer
           </label>
       </span>
    </div>
</fieldset>

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.