Я недавно перешел на postgresql, так как позже мне придется развернуть свое приложение на heroku.
Но у меня возникают некоторые проблемы.
Мое действие Создать для смены модели не работаетбольше:
Сообщение об ошибке:
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 %>
РЕДАКТИРОВАТЬ: Код выбора времени:
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