ruby on rails:如何在表单中输入哈希值?

时间:2018-02-26 13:51:31

标签: ruby-on-rails ruby hash

问题:我想将地址保存为哈希,但我无法在/_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]

0 个答案:

没有答案