Ruby: Trying to "Update_all" but getting "NameError: uninitialized constant" -
Ruby: Trying to "Update_all" but getting "NameError: uninitialized constant" -
this first time seek write ruby migration script (i want update value of col specific row).
i have table called "events" cols "e_id" , "e_text_en". want update "e_text_en" value of row id 6. in sql be
update events set e_text_en = 'blabla' e_id = 6;
my ruby approach: (20141013130000_update_broken_event_texts.rb)
class updatebrokentextseventinevent < activerecord::migration def events.up events.where('e_id', 6).update_all(e_text_en: "blablabla") end end
but gives me error ´nameerror: uninitialized constant´
rake aborted! nameerror: uninitialized constant updatebrokentextseventinevent::events /var/.../20141013130000_update_broken_event_texts.rb:2:in `<class:updatebrokentextseventinevent>' /var/.../20141013130000_update_broken_event_texts.rb:1:in `<top (required)>' /var/lib/gems/1.9.1/gems/activerecord-4.0.1/lib/active_record/migration.rb:718:in `load_migration' /var/lib/gems/1.9.1/gems/activerecord-4.0.1/lib/active_record/migration.rb:714:in `migration' /var/lib/gems/1.9.1/gems/activerecord-4.0.1/lib/active_record/migration.rb:708:in `disable_ddl_transaction' /var/lib/gems/1.9.1/gems/activerecord-4.0.1/lib/active_record/migration.rb:1012:in `use_transaction?' /var/lib/gems/1.9.1/gems/activerecord-4.0.1/lib/active_record/migration.rb:922:in `rescue in block in migrate' /var/lib/gems/1.9.1/gems/activerecord-4.0.1/lib/active_record/migration.rb:919:in `block in migrate' /var/lib/gems/1.9.1/gems/activerecord-4.0.1/lib/active_record/migration.rb:916:in `each' /var/lib/gems/1.9.1/gems/activerecord-4.0.1/lib/active_record/migration.rb:916:in `migrate' /var/lib/gems/1.9.1/gems/activerecord-4.0.1/lib/active_record/migration.rb:764:in `up' /var/lib/gems/1.9.1/gems/activerecord-4.0.1/lib/active_record/migration.rb:742:in `migrate' /var/lib/gems/1.9.1/gems/activerecord-4.0.1/lib/active_record/railties/databases.rake:42:in `block (2 levels) in <top (required)>' tasks: top => db:migrate
while searched solution found advises tables called in singular, when seek event
instead of events
same error.
can help me right ruby?
versions used:
$ rails -v rails 4.0.1 $ gem -v 1.8.23.2 $ ruby -v ruby 1.9.3p545 (2014-02-24) [i686-linux] brightbox
edit: addional infos our schema created via sql-file. started utilize migrations short time ago , first update-one. first 2 migrations table-changes. don't have ´app/model´ files yet, becuase other migrations worked without any, e.g.:
class adddeliveriestoemailqueue < activerecord::migration def alter add_column :email_queue, :deliveries, :int, :null => false, :default => 0, :after => :error end end
this mutual problem when create migration , deside rename it. class name in migration should same filename. have migration class updatebrokentextseventinevent
, filename 20141013130000_update_broken_event_texts.rb
, class name should updatebrokeneventtexts
.
ruby-on-rails ruby
Comments
Post a Comment