2011-12-13 5 views
0

私は最近、herokuに自分のアプリを配備する必要があるので、私は最近postgresqlに移行しました。postgresqlへの移行 - アクションの作成がもう機能しない

しかし、私はいくつかの問題に遭遇しています。

はもう動作しない機種シフトのためのアクションを作成します。マイ:

エラーメッセージは次のとおりです。

2 error(s) on assignment of multiparameter attributes 

モデル:

class Shift < ActiveRecord::Base 
    attr_accessible :starts_at, :ends_at, :happens_on, :employee_id 

    belongs_to :employee 
    has_one :company, :through => :employee 

    validates :employee_id, :presence => true 


    validates :happens_on, :presence => true 
    validates :starts_at, :presence => true 
    validates :ends_at, :presence => true 
end 

コントローラのアクション "作成":

def create 
    @title = "New Shift"  

    @shift = Shift.new(params[:shift])   

    if @shift.save 
    redirect_to shifts_path, :flash => { :success => 'Shift created!' } 
    else 
    render action: "new" 
    end 
end 
{"utf8"=>"✓", 
"authenticity_token"=>"dH017fvWEGUWj3VPi7TssjL3BpjxzcC4Idjjc=", 
"shift"=>{"employee_id"=>"3", 
"happens_on"=>"12/15/2011", 
"starts_at(5i)"=>"06:00:00", 
"ends_at(5i)"=>"09:30:00"}, 
    "commit"=>"Create Shift"} 

そして、私のフォーム::

<%= simple_form_for @shift, :wrapper => :inline do |f| %> 

<% if f.error_notification %> 
<div class="alert-message error fade in" data-alert="alert"> 
<a class="close" href="#">×</a> 
<p><%= f.error_notification %></p> 
</div> 
<% end %> 

<%= f.association :employee, :input_html => { :class => "span4" }%> 
<%= f.input :happens_on, :input_html => { :class => "span4" }, :as => :date_picker %> 
<div class="clearfix"> 
<label for="shift_starts_at_5i">Start Time</label> 
<div class="input"><%= time_select "shift", "starts_at", { :default => Time.now.change(:hour => 21), :simple_time_select => true, :minute_interval => 30, :time_separator => "", :start_hour => 6, :end_hour => 20 } %> 
</div></div> 
<div class="clearfix"> 
<label for="shift_ends_at_5i">End Time</label> 
<div class="input"><%= time_select "shift", "ends_at", { :default => Time.now.change(:hour => 21), :simple_time_select => true, :minute_interval => 30, :time_separator => "", :start_hour => 6, :end_hour => 20 } %> 
</div></div> 

    <div class="actions"> 
     <%= f.button :submit, :class => 'primary' %> 
     <%= button_tag 'Cancel', :type => :reset, :class => "btn" %> 
    </div> 
<% end %> 

EDIT:time_selectの コード:パラメータ取得

module ActionView::Helpers 
    class DateTimeSelector 
     def select_minute_with_simple_time_select 
      return select_minute_without_simple_time_select unless @options[:simple_time_select].eql? true 

      # Although this is a datetime select, we only care about the time. Assume that the date will 
      # be set by some other control, and the date represented here will be overriden 

      val_minutes = @datetime.kind_of?(Time) ? @datetime.min + @datetime.hour*60 : @datetime 

      @options[:time_separator] = "" 

      # Default is 15 minute intervals 
      minute_interval = 15 
      if @options[:minute_interval] 
      minute_interval = @options[:minute_interval] 
      end 

      start_minute = 0 
      # @options[:start_hour] should be specified in military 
      # i.e. 0-23 
      if @options[:start_hour] 
      start_minute = @options[:start_hour] * 60 
      end 

      end_minute = 1439 
      # @options[:end_hour] should be specified in military 
      # i.e. 0-23 
      if @options[:end_hour] 
      end_minute = (@options[:end_hour] + 1) * 60 - 1 
      end 

      if @options[:use_hidden] || @options[:discard_minute] 
      build_hidden(:minute, val) 
      else 
      minute_options = [] 
      start_minute.upto(end_minute) do |minute| 
       if minute%minute_interval == 0 
       ampm = minute < 720 ? ' AM' : ' PM' 
       hour = minute/60 
       minute_padded = zero_pad_num(minute%60) 
       hour_padded = zero_pad_num(hour) 
       ampm_hour = ampm_hour(hour) 

       val = "#{hour_padded}:#{minute_padded}:00" 
       minute_options << ((val_minutes == minute) ? 
        %(<option value="#{val}" selected="selected">#{ampm_hour}:#{minute_padded}#{ampm}</option>\n) : 
        %(<option value="#{val}">#{ampm_hour}:#{minute_padded}#{ampm}</option>\n) 
       ) 
       end 
      end 
      build_select(:minute, minute_options.join(' ')) 
      end 
     end 
     alias_method_chain :select_minute, :simple_time_select 


     def select_hour_with_simple_time_select 
      return select_hour_without_simple_time_select unless @options[:simple_time_select].eql? true 
      # Don't build the hour select 
      #build_hidden(:hour, val) 
     end 
     alias_method_chain :select_hour, :simple_time_select 

     def select_second_with_simple_time_select 
      return select_second_without_simple_time_select unless @options[:simple_time_select].eql? true 
      # Don't build the seconds select 
      #build_hidden(:second, val) 
     end 
     alias_method_chain :select_second, :simple_time_select 

     def select_year_with_simple_time_select 
      return select_year_without_simple_time_select unless @options[:simple_time_select].eql? true 
      # Don't build the year select 
      #build_hidden(:year, val) 
     end 
     alias_method_chain :select_year, :simple_time_select 

     def select_month_with_simple_time_select 
      return select_month_without_simple_time_select unless @options[:simple_time_select].eql? true 
      # Don't build the month select 
      #build_hidden(:month, val) 
     end 
     alias_method_chain :select_month, :simple_time_select 

     def select_day_with_simple_time_select 
      return select_day_without_simple_time_select unless @options[:simple_time_select].eql? true 
      # Don't build the day select 
      #build_hidden(:day, val) 
     end 
     alias_method_chain :select_day, :simple_time_select 

    end 
    end 

    def ampm_hour(hour) 
    return hour == 12 ? 12 : (hour == 0 ? 12 : (hour/12 == 1 ? hour % 12 : hour)) 
    end 

    def zero_pad_num(num) 
    return num < 10 ? '0' + num.to_s : num.to_s 
    end 

答えて

1

は、私はあなたが不満を取得していることを推測すると思いますstarts_at(5i)ends_at(5i)であり、starts_atends_atの両方がdatetimesまたはtimestampsとして定義されていることを確認してください。私はあなたもSQLiteから来ていると思います。 SQLiteは非常に緩やかな型システムを持っていますが、PostgreSQLは非常に厳しいです。 '06:00:00'をPostgreSQLのタイムスタンプ列に入れると、タイムスタンプに日付と時刻の両方のコンポーネントが必要となるため、PostgreSQLはエラーになります。

上記の場合は、移行中にこのようなものは、トリックを行う可能性がある、シンプルtime列にあなたのstarts_atends_at列を変更してみてください、その後、右です:

def up 
    change_column :shifts, :starts_at, :time, ... 
    change_column :shifts, :ends_at, :time, ... 
end 
関連する問題