【发布时间】:2013-10-03 23:22:16
【问题描述】:
我第一次在 rails4 应用程序中使用 Hstore,我在表单中使用 javascript 为 hstore 列 (:schema) 构建动态表单字段
在 rails 4 中,我不需要在我的模型中添加任何 setter/getter 方法,对吗?
在我的表单中,我正在构建动态输入字段并允许用户设置键/值对。很像Hstore Heroku Demo App
所以基本上我的表单会有类似的输入
input name="app[schema][dynamic_key1]" value="whatever value"
input name="app[schema][dynamic_key2]" value="whatever value2"
在我的应用控制器中:
def app_params
params.require(:app).permit(:name, :title, :schema )
end
但是,当我创建新的 App 记录时,我的架构 hstore 值没有保存。我看到了一些关于为 :schema => [] 制作强参数的事情,但这仍然不起作用。
由于我不知道这些值是什么,我无法像在很多示例中看到的那样为这些设置 store_accessors。
【问题讨论】:
-
您能否为布局/控制器添加(form_for 的重要部分)完整代码?
标签: ruby-on-rails postgresql ruby-on-rails-4 hstore