Ruby on rails rails 3.2冰块和循环冰块选择

Ruby on rails rails 3.2冰块和循环冰块选择,ruby-on-rails,ruby,Ruby On Rails,Ruby,我正在尝试将一个循环的\u select保存到一个序列化属性,以处理rails应用程序上的循环事件。 使用我可以保存日程安排,但现在无法保存日程安排 属性显示在“索引”视图中,或在“表单”视图中更新“定期选择” 这是我的模型 class Todo < ActiveRecord::Base attr_accessible :item, :completed, :schedule, :start_date after_initialize :default_values val

我正在尝试将一个循环的\u select保存到一个序列化属性,以处理rails应用程序上的循环事件。 使用我可以保存日程安排,但现在无法保存日程安排 属性显示在“索引”视图中,或在“表单”视图中更新“定期选择”

这是我的模型

class Todo < ActiveRecord::Base

  attr_accessible :item, :completed, :schedule, :start_date
  after_initialize :default_values

  validates :item, presence: true
  belongs_to :list 

  belongs_to :tasklib,
             :foreign_key=>"item"

  #recuring model 
  include ActiveModel::Validations
  include ActiveModel::Conversion
  extend ActiveModel::Naming

  attr_accessor :schedule

  serialize :schedule, Hash

  def schedule=(new_schedule)
     write_attribute(:schedule,RecurringSelect.dirty_hash_to_rule(new_schedule).to_hash)
  end

  def converted_schedule
    the_schedule = Schedule.new(self.start_date)
    the_schedule.add_recurrence_rule(RecurringSelect.dirty_hash_to_rule(self.schedule))
    the_schedule
  end

end
classtodo“项”
#重现模型
包括ActiveModel::验证
包含ActiveModel::转换
扩展ActiveModel::命名
属性存取器:计划
序列化:计划、哈希
def计划=(新的_计划)
write_属性(:schedule,RecurringSelect.dirty_hash_to_规则(新_schedule.to_hash)
结束
def转换表
_计划=schedule.new(self.start_日期)
_schedule.add_recurrence_规则(RecurringSelect.dirty_hash_to_规则(self.schedule))
课程表
结束
结束
这是我的索引视图:

h1><%= @list.name %></h1>
<table class="table table-striped">
  <thead>
    <tr>    
      <th><%= model_class.human_attribute_name(:item) %></th>
      <th><%= model_class.human_attribute_name(:start_date) %></th>      
      <th><%= model_class.human_attribute_name(:schedule) %></th>      
      <th><%=t '.actions', :default => t("helpers.actions") %></th>
    </tr>
  </thead>
  <tbody>
    <% @list.todos.each do |todo| %>
      <tr>        
        <td><%= todo.item %></td>
        <td><%= todo.start_date %></td>        
        <td><%= todo.schedule %></td>

        <td>
          <%= link_to t('.edit', :default => t("helpers.links.edit")),
                      edit_list_todo_path(@list, todo), :class => 'btn btn-mini' %>
          <%= link_to t('.destroy', :default => t("helpers.links.destroy")),
                      list_todo_path(@list, todo),
                      :method => :delete,
                      :confirm => t('.confirm', :default => t("helpers.links.confirm", :default => 'Are you sure?')),
                      :class => 'btn btn-mini btn-danger' %>
        </td>
      </tr>
    <% end %>
  </tbody>
</table>
h1>
t(“helpers.actions”)%>
t(“helpers.links.edit”),
编辑路径(@list,todo),:class=>'btn btn mini'>
t(“helpers.links.destroy”),
list_todo_路径(@list,todo),
:method=>:delete,
:confirm=>t('.confirm',:default=>t(“helpers.links.confirm”,:default=>'确定吗?),
:class=>“btn btn迷你btn危险”%>
这是我的观点:

<%= simple_form_for [@list, if @todo.nil? then @list.todos.build else @todo end], :html => { :class => 'form-horizontal' } do |f| %>

  <%-# f.input :item, input_html: {class: "span6", rows: 3}  -%>

  <%= f.collection_select :item, Tasklib.order(:name),:name,:name, include_blank: true %>

  <%= f.label :start_date, "date" %>
  <%= f.input :start_date %>

  <%= f.label :schedule %>
  <%= f.select_recurring :schedule, nil, :allow_blank => true %>

  <div class="form-actions">
    <%= f.submit 'Save', :class => 'btn btn-primary' %>
    <%= link_to t('.cancel', :default => t("helpers.links.cancel")),
                lists_path, :class => 'btn' %>
  </div>
<% end %>
{:class=>'form horizontal'}do | f |%>
正确%>
“btn btn主节点”%>
t(“helpers.links.cancel”),
列出路径:class=>'btn'>
好的,我找到了! 模型应为:

  def schedule=(new_schedule)
     if new_schedule == nil 
       new_schedule = IceCube::Schedule.new( self.start_date )
     end  

     write_attribute(:schedule, RecurringSelect.dirty_hash_to_rule(new_schedule).to_hash)
  end


  def converted_schedule
     if !self.read_attribute(:schedule).empty?
     the_schedule = IceCube::Schedule.new( self.start_date )
     the_rule    = RecurringSelect.dirty_hash_to_rule( self.read_attribute(:schedule) )
     if RecurringSelect.is_valid_rule?(the_rule)
       the_schedule.add_recurrence_rule( the_rule)
     end
     the_schedule
    end

  end
表单视图应仅设置一个新的循环选择,如:

  <%= f.select_recurring :schedule, [ ["No recurring", "{}"] ], :allow_blank => true %>
true%>