我想用form_for(text_area)更新哈希。
我的数据库:
class CreateEvents < ActiveRecord::Migration[5.0]
def change
create_table :events do |t|
t.text :description
t.timestamps
end
end
模块:
class Event < ApplicationRecord
serialize :description, Hash
end
db中的描述哈希:
description = {:en => "English", :es => "Spanish", :it => "Italian"}
当我想用英语阅读说明时,我会这样做:
@event.description[:en]
但问题是当我需要创建或更新描述哈希时。我试过这个:
form_for(@event) do |e|
e.label :description, "Description EN"
e.text_area :description[:en]
e.label :description, "Description ES"
e.text_area :description[:es]
e.submit
end
但它不起作用。如何在form_for?
中编辑/创建哈希变量