Rails アプリケーションに、投稿の公開日 (時間ではなく) を変更するためのフォーム要素があります。これを行ったのは、jquery-ui の datepicker 要素を使用して、時間のドロップダウン メニューを表示できるようにするためです。
「updated_at」属性を公開日に更新したいです。ただし、エラーが発生します。
PG::Error: ERROR: null value in column "updated_at" violates not-null constraint
: UPDATE "steps" SET "updated_at" = NULL WHERE "steps"."id" = 472
これが私のフォームです(時間を正しく保存できますが、日付は保存できません):
<%= semantic_form_for [@project, @step], :html => {:multipart => true} do |f| %>
<%= f.inputs do%>
<div id="publishedOn">
<span class="label" style="margin-left:9px">Published on</span>
<%= f.text_field :published_on, :value=> (@step.updated_at.strftime("%m/%d/%Y")) %> at <%= f.time_select :updated_at, :class=>"btn dropdown-toggle", :ampm=> true, :ignore_date=>true%>
</div>
<% end %>
steps_controller:
def update
@step = @project.steps.find_by_position(params[:id])
published = String(params[:published_on])
published = published.gsub("/", "-")
@step.update_attributes(:updated_at => published)
end
step.rb:
class Step < ActiveRecord::Base
extend FriendlyId
friendly_id :position
has_ancestry :orphan_strategy => :adopt
attr_accessible :description, :name, :position, :project_id, :images_attributes, :parent_id, :ancestry, :updated_at, :published_on
belongs_to :project
has_many :images, :dependent => :destroy
accepts_nested_attributes_for :images, :allow_destroy => :true
validates :name, :presence => true
end
updated_at 日付を更新するには、published_on 日付パラメーターを再フォーマットする必要がありますか?