Ruby on rails 轨道&x2B;自定义动态键
RABL是否可以动态设置密钥名称?我正在尝试以以下格式输出Ruby on rails 轨道&x2B;自定义动态键,ruby-on-rails,json,rabl,Ruby On Rails,Json,Rabl,RABL是否可以动态设置密钥名称?我正在尝试以以下格式输出 snippet_1: {name: 'map', options: {'options[postcode]': "SW64TY"}}, snippet_2: {name: 'map', options: {'options[postcode]': "GU78YU"}} 在rabl的观点中,我有以下几点: collection @snippets => 'snippets' attribute :snippet_type =>
snippet_1: {name: 'map', options: {'options[postcode]': "SW64TY"}}, snippet_2: {name: 'map', options: {'options[postcode]': "GU78YU"}}
在rabl的观点中,我有以下几点:
collection @snippets => 'snippets'
attribute :snippet_type => :name
attribute :options => :options
attribute :snippet_id => :id
我的桌子看起来像:
create_table "snippet_instances", :force => true do |t|
t.string "snippet_type"
t.text "options"
t.integer "page_id"
t.string "snippet_id"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
end
选项被序列化
非常感谢