Giter VIP home page Giter VIP logo

enum_column's People

Contributors

electronick avatar jmcnally avatar mmichaa avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

enum_column's Issues

Does not seem to work with `validates :gender, :inclusion => { :in => %w{male female} }`

I banged my head against the screen while trying to get validates :gender, :inclusion => { :in => %w{male female} } to work, while :gender was an :enum field. But validations just don't pass. When doing the same with a normal :string field, everything works.

Migration:

class CreatePlayers < ActiveRecord::Migration
  def change
    create_table :players do |t|
      t.string :name
      t.enum :gender, :limit => [:male, :female], :default => :male
      t.string :gender2

      t.timestamps
    end
  end
end

Model:

class Player < ActiveRecord::Base
  validates :gender, :inclusion => { :in => %w{male female} }
  validates :gender2, :inclusion => { :in => %w{male female} }
end

Here some code which demonstrates the problem:

1.9.3p0 :001 > p = Player.new
 => #<Player id: nil, name: nil, gender: :male, gender2: nil, created_at: nil, updated_at: nil> 
1.9.3p0 :002 > p.valid?
 => false 
1.9.3p0 :003 > p.errors
 => #<ActiveModel::Errors:0x007ff55601e1d8 @base=#<Player id: nil, name: nil, gender: :male, gender2: nil, created_at: nil, updated_at: nil>, @messages={:gender=>["ist nicht in der Liste vorhanden!"], :gender2=>["ist nicht in der Liste vorhanden!"]}> 
1.9.3p0 :004 > p.gender = 'male'
 => "male" 
1.9.3p0 :005 > p.gender2 = 'male'
 => "male" 
1.9.3p0 :006 > p.valid?
 => false 
1.9.3p0 :007 > p.errors
 => #<ActiveModel::Errors:0x007ff55601e1d8 @base=#<Player id: nil, name: nil, gender: :male, gender2: "male", created_at: nil, updated_at: nil>, @messages={:gender=>["ist nicht in der Liste vorhanden!"]}>

rake db:schema:dump not generating enums in Rails 3.1.0

I'm not certain, but I suspect there may be some incompatibilities between enum_column and the updated mysql2 gems that manifest in Rails 3.1.0:

In a Rails 3.0.9 project, I can "rake db:schema:dump" and get nice enum columns from the database. In my Rails 3.1.0 project, "rake db:schema:dump" generates the same broken schema.rb files as you'd get without using the enum_column library.

I suspect that, since Rails 3.1.0 apparently includes the MySQL adapter by default, and the mysql2 gem no longer includes it (as evidenced by the fact that Rails 3.0.9 doesn't work if you've got a version of mysql2 >= 0.3) this has changed things just enough that the dumper isn't taking advantage of enum_column anymore...

I'll keep poking, but if anyone can repro this, or can figure out what I've done wrong, I'll be very happy. :)

Enum_select includes blank option for null.

Even though I would like to use the enum_select option I end up having to do.
f.select(:color, Enumeration.columns_hash['color'].limit, :prompt => "Choose Color")
instead of
f.enum_select(:color, :prompt => "Choose Color")
because the latter creates Choose Color and .

Plugin generates error with Rails 3.2

c:/idjet/Ruby192/lib/ruby/gems/1.9.1/gems/enum_column3-0.1.3/lib/enum/enum_adapter.rb:8:in <top (required)>': uninitialized constant ActiveRecord::ConnectionAdapters::Mysq lColumn (NameError) from c:/idjet/Ruby192/lib/ruby/gems/1.9.1/gems/enum_column3-0.1.3/lib/enum_column.rb:6:inblock (2 levels) in class:EnumColumnRailtie'
from c:/idjet/Ruby192/lib/ruby/gems/1.9.1/gems/activesupport-3.2.1/lib/active_support/lazy_load_hooks.rb:36:in instance_eval' from c:/idjet/Ruby192/lib/ruby/gems/1.9.1/gems/activesupport-3.2.1/lib/active_support/lazy_load_hooks.rb:36:inexecute_hook'
from c:/idjet/Ruby192/lib/ruby/gems/1.9.1/gems/activesupport-3.2.1/lib/active_support/lazy_load_hooks.rb:43:in `block in run_load_hooks'

enum_select error

I added enum_column3 to my gemfile for a rails 3.01 project, installed it with bundler, and created and ran a migration. I confirmed in the rails console that the column was created as expected. Here is the error output:

undefined local variable or method `enum' for #ActionView::Helpers::InstanceTag:0x29e7f94
Extracted source (around line #24):

21:
22:


23: <%= f.label :subject %>

24: <%= f.enum_select :subject %>
25:

I have traced it to line 34 in active_record_helper.rb:

31:  if (value = self.object.__send__(method_name.to_sym))
32:    options[:selected] ||= value.to_s
33:  else
34:    options[:include_blank] = enums.allows_nil? if options[:include_blank].nil?
35:  end

enums is not defined or referenced anywhere outside line 34.

Support stand-alone ActiveRecord

I'm attempting to use this gem in a project which uses ActiveRecord in isolation, but it doesn't seem possible due to the if ::Rails::Railtie condition wrapping the code in enum_column.rb. Without this, my schema dumps don't pick up the enum.

Gemspec Version regressed

Hey! I'm trying to install from git source and things worked fine until recently...I now get:

Could not find gem 'enum_column (>= 0)' in git://github.com/electronick/enum_column.git (at master).

I think in messing around with the Gemspec recently it might have broken. In addition, I looked at your commit history and it seems to go from 0.7.x to 0.1.x, I don't think that's good :-P Hopefully that's enough for you to track it down. Thanks again for the awesome gem!

Add / Edit enum

Is there a way to add enum's to existing tables?

Also If I need to add a new value to the enum what is the syntax.

I want to change an enum column from
From
status ('pending', 'active')
To
status ('pending', 'active', 'canceled')


and can I do something like this?

add_column :status, :enum, :limit => [:casual, :formal, :wild, :sports, :neutral, :colorful]

This is incompatible with rails 4.2

enum_column3-0.1.4/lib/enum/enum_adapter.rb:30:in block in <top (required)>': undefined methodtype_cast' for class `ActiveRecord::ConnectionAdapters::AbstractMysqlAdapter::Column' (NameError)

"Unrails" the gem so that it works outside of rails as well

Hi

I have an issue here. I want to use AR in Sinatra (or Merb, for that matter), but the initialization of the gem is done in a Railstie block. Is it for some special reason like that? I would say that the only dependency of this gem is ActiveRecord (or mysql adapter, since enum is a mysql-only property), and therefore, by unrails it, you'd be having the gem used in more application (non-Rails as well).

By the way, my short-term solution was to put whatever was on the Railstie block in an initializer. A bit overkill, for now.

Error on Rails 3.2.6

I get the following:

~/workspace/pro (master) $ rake db:init_partial --trace
rake aborted!
undefined method to_tag' for classActionView::Helpers::InstanceTag'
/Users/aaron/.rvm/gems/ruby-1.9.3-p125@pro/gems/enum_column-0.1.6/lib/enum_column/active_record_helper.rb:38:in <class:InstanceTag>' /Users/aaron/.rvm/gems/ruby-1.9.3-p125@pro/gems/enum_column-0.1.6/lib/enum_column/active_record_helper.rb:37:inmodule:Helpers'
/Users/aaron/.rvm/gems/ruby-1.9.3-p125@pro/gems/enum_column-0.1.6/lib/enum_column/active_record_helper.rb:3:in <module:ActionView>' /Users/aaron/.rvm/gems/ruby-1.9.3-p125@pro/gems/enum_column-0.1.6/lib/enum_column/active_record_helper.rb:2:in<top (required)>'
/Users/aaron/.rvm/gems/ruby-1.9.3-p125@pro/gems/activesupport-3.2.6/lib/active_support/dependencies.rb:251:in require' /Users/aaron/.rvm/gems/ruby-1.9.3-p125@pro/gems/activesupport-3.2.6/lib/active_support/dependencies.rb:251:inblock in require'
/Users/aaron/.rvm/gems/ruby-1.9.3-p125@pro/gems/activesupport-3.2.6/lib/active_support/dependencies.rb:236:in load_dependency' /Users/aaron/.rvm/gems/ruby-1.9.3-p125@pro/gems/activesupport-3.2.6/lib/active_support/dependencies.rb:251:inrequire'
/Users/aaron/.rvm/gems/ruby-1.9.3-p125@pro/gems/enum_column-0.1.6/lib/enum_column.rb:10:in <top (required)>' /Users/aaron/.rvm/gems/ruby-1.9.3-p125@pro/gems/bundler-1.1.4/lib/bundler/runtime.rb:68:inrequire'
/Users/aaron/.rvm/gems/ruby-1.9.3-p125@pro/gems/bundler-1.1.4/lib/bundler/runtime.rb:68:in block (2 levels) in require' /Users/aaron/.rvm/gems/ruby-1.9.3-p125@pro/gems/bundler-1.1.4/lib/bundler/runtime.rb:66:ineach'
/Users/aaron/.rvm/gems/ruby-1.9.3-p125@pro/gems/bundler-1.1.4/lib/bundler/runtime.rb:66:in block in require' /Users/aaron/.rvm/gems/ruby-1.9.3-p125@pro/gems/bundler-1.1.4/lib/bundler/runtime.rb:55:ineach'
/Users/aaron/.rvm/gems/ruby-1.9.3-p125@pro/gems/bundler-1.1.4/lib/bundler/runtime.rb:55:in require' /Users/aaron/.rvm/gems/ruby-1.9.3-p125@pro/gems/bundler-1.1.4/lib/bundler.rb:119:inrequire'
/Users/aaron/workspace/pro/config/application.rb:63:in <top (required)>' /Users/aaron/.rvm/rubies/ruby-1.9.3-p125/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:inrequire'
/Users/aaron/.rvm/rubies/ruby-1.9.3-p125/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in require' /Users/aaron/workspace/pro/Rakefile:5:in<top (required)>'
/Users/aaron/.rvm/gems/ruby-1.9.3-p125@global/gems/rake-0.9.2.2/lib/rake/rake_module.rb:25:in load' /Users/aaron/.rvm/gems/ruby-1.9.3-p125@global/gems/rake-0.9.2.2/lib/rake/rake_module.rb:25:inload_rakefile'
/Users/aaron/.rvm/gems/ruby-1.9.3-p125@global/gems/rake-0.9.2.2/lib/rake/application.rb:501:in raw_load_rakefile' /Users/aaron/.rvm/gems/ruby-1.9.3-p125@global/gems/rake-0.9.2.2/lib/rake/application.rb:82:inblock in load_rakefile'
/Users/aaron/.rvm/gems/ruby-1.9.3-p125@global/gems/rake-0.9.2.2/lib/rake/application.rb:133:in standard_exception_handling' /Users/aaron/.rvm/gems/ruby-1.9.3-p125@global/gems/rake-0.9.2.2/lib/rake/application.rb:81:inload_rakefile'
/Users/aaron/.rvm/gems/ruby-1.9.3-p125@global/gems/rake-0.9.2.2/lib/rake/application.rb:65:in block in run' /Users/aaron/.rvm/gems/ruby-1.9.3-p125@global/gems/rake-0.9.2.2/lib/rake/application.rb:133:instandard_exception_handling'
/Users/aaron/.rvm/gems/ruby-1.9.3-p125@global/gems/rake-0.9.2.2/lib/rake/application.rb:63:in run' /Users/aaron/.rvm/gems/ruby-1.9.3-p125@global/gems/rake-0.9.2.2/bin/rake:33:in<top (required)>'
/Users/aaron/.rvm/gems/ruby-1.9.3-p125@global/bin/rake:19:in load' /Users/aaron/.rvm/gems/ruby-1.9.3-p125@global/bin/rake:19:in

'

Schema dump issues

Using the gem, all migrations work and the columns are being updated to Enum columns. (using mysql)
When I migrate the DB, the schema does not get dumped correctly and I get a warning that the table can't be dumped.

Once I change the field back to string, everything goes back to normal.

Using Ruby 1.9.2, Rails 3.0.9

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.