问题:我想将地址保存为哈希,但我无法在/_form
中对其进行编辑。如何正确访问哈希/_form
中的键/值?
我有一个客户端模型:
class Client < ActiveRecord::Base
serialize :address, Hash
end
clients_controller:
def client_params
params.require(:client).permit(:name, {:address => [:street, :city]})
end
的客户机/ _form:
= simple_form_for(@client) do |f|
= f.input :name
= f.simple_fields_for :address do |t|
= t.input :city
= t.input :street
= f.button :submit
必须是:
= t.input :address["city"]
= t.input :'address["city"]'', id: :start
另外,如何指定默认密钥?在Client.rb
中会出现类似的情况吗?
store :address, accessors: [ :city, :address]