Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/53.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails Can';无法使ActiveRecord::Store在表单中工作_Ruby On Rails_Ruby On Rails 3.2 - Fatal编程技术网

Ruby on rails Can';无法使ActiveRecord::Store在表单中工作

Ruby on rails Can';无法使ActiveRecord::Store在表单中工作,ruby-on-rails,ruby-on-rails-3.2,Ruby On Rails,Ruby On Rails 3.2,ActiveRecord::Store在更高版本的3.2中是否已更改?我在搜索中找不到很多关于它的信息。有些人认为它很棒,有些人认为它很棒 意见。有一些早期3.2版本的博客条目,大多数只是使用控制台更新ActiveRecord::Store中的属性。有 少许 将其与表单一起使用的示例/教程。大多数人使用存储属性就像使用列一样,但我无法让它工作。也无法让一些控制台示例正常工作 class Stage < ActiveRecord::Base AD_ATTR = [:job_area, :

ActiveRecord::Store在更高版本的3.2中是否已更改?我在搜索中找不到很多关于它的信息。有些人认为它很棒,有些人认为它很棒 意见。有一些早期3.2版本的博客条目,大多数只是使用控制台更新ActiveRecord::Store中的属性。有 少许 将其与表单一起使用的示例/教程。大多数人使用存储属性就像使用列一样,但我无法让它工作。也无法让一些控制台示例正常工作

class Stage < ActiveRecord::Base
  AD_ATTR = [:job_area, :end_date, :ad_url, :instructions, :other]
  store :ad, :assessors => AD_ATTR
  attr_accessible *AD_ATTR, :date, :enterable, :est_candidates, :name, :status, :program_id, :sequence
end

# I've also tried it without the * and defining each accessor
使用此方法,您还可以将其他对象放入值中,有些人已经有了gemstore\u字段。我对你的不满 至少我可以使用ActiveRecord::Store进行评估


史蒂夫

你找到更好的解决方案了吗?我放弃了::商店。如果我想在一个模型中序列化一个列中的散列(本例中为:data),那么我最终只使用serialize:data和JSON。
1.9.2-p136 :752 > s = Stage.find(1)
 => #<Stage id: 1, ... , ad: {}, sequence: 1> 
1.9.2-p136 :753 > s.ad
 => {} 
1.9.2-p136 :754 > s.other
NoMethodError: undefined method `other' for #<Stage:0x00000103de4528>

1.9.2-p136 :755 > s.ad[:other]
 => nil 

1.9.2-p136 :756 > s.other = "stuff"
NoMethodError: undefined method `other=' for #<Stage:0x00000103de4528>

1.9.2-p136 :757 > s.ad[:other] = "stuff"
 => "stuff" 
1.9.2-p136 :758 > a.other
NoMethodError: undefined method `other' for #<Take::Assessment:0x000001038ba778>
<tr class="field">
  <th><%= f.label :other %></th>
  <td><%= f.text_field :other %></td>
</tr>
undefined method 'other' for #<Stage:0x0000010396a650>
<%= fields_for :ad_fields do |a| %>
  <tr class="field">
    <th><%= a.label :other %></th>
    <td><%= a.text_field :other, :value => @stage.ad[:other] %></td>
  </tr>

  <tr class="field">
    <th><%= a.label :job_area %></th>
    <td><%= a.text_field :job_area, :value => @stage.ad[:job_area] %></td>
  </tr>

<% end %>
def update
  @stage = Stage.find(params[:id])
  respond_to do |format|
    if params[:ad_fields]
      params[:ad_fields].each do |key,value|
        @stage.ad[key.to_sym] = value
      end
    end
    if @stage.update_attributes(params[:stage])
    ...
  end