我有一个Event带有日期时间列的ActiveRecord模型starts_at.我想提交一份表格,其中日期和时间starts_at分别选择(例如"23-10-2010"日期和"18:00"时间).这些字段应该由单列支持starts_at,并且验证也应该优选地反对starts_at.
我当然可以使用虚拟属性和钩子,但我想要一个更优雅的解决方案.我已经尝试了composed_of(rdoc)和属性装饰器(灯塔讨论,github)但没有成功.
以下是我想要的概述.
class Event < ActiveRecord::Base
validates_presence_of :start_date
end
# View
# On submission this should set start_date.
form_for @event do |f|
f.text_field :starts_at_date # date-part of start_date
f.text_field :starts_at_time_of_day # time-of-day-part of start_date
f.submit
end
Run Code Online (Sandbox Code Playgroud)
任何帮助赞赏.
我有一个标题doc.at('head/title').inner_html,&应该是&.
我的原始文件是:
<head><title>Foo & Bar</title></head>
Run Code Online (Sandbox Code Playgroud)
但是如下所示:
>> doc = Nokogiri::HTML.parse(file, nil, "UTF-8")
>> doc.at('head/title')
=> #<Nokogiri::XML::Element:0x..fdb851bea name="title" children=#<Nokogiri::XML::Text:0x..fdb850808 "Foo & Bar">>
>> doc.at('head/title').inner_html
=> "Foo & Bar"
Run Code Online (Sandbox Code Playgroud)
我不想使用Iconv或CGI:
>> require 'cgi'
>> CGI.unescapeHTML(doc.at('head/title').inner_html)
=> "Foo & Bar"
Run Code Online (Sandbox Code Playgroud)
这是丑陋和不方便的.