我在Rails 4应用程序中使用Simple_form.
如何在与模型无关的视图中显示错误消息?
我希望得到与基于模型的其他视图相同的结果.
现在,这是视图中的代码:
<%= simple_form_for(:registration, html: { role: 'form' }, :url => registrations_path) do |f| %>
<%= f.error_notification %>
<%= f.input :name, :required => true, :autofocus => true %>
<%= f.input :email, :required => true %>
<%= f.input :password, :required => true %>
<%= f.input :password_confirmation, :required => true %>
<%= f.button :submit %>
<% end %>
Run Code Online (Sandbox Code Playgroud)
在"正常"视图中(即使用模型),行<%= f.error_notification %>显示错误.
我应该怎么做我的控制器初始化Simple_form使用的东西来显示错误?
谢谢
我根据请求使用TimeZone在Ruby on Rails 4中开发应用程序.
我想在我的应用程序中使用日期时间选择器(http://xdsoft.net/jqplugins/datetimepicker/)来替换默认的Simple_form日期时间输入(5个组合框...).
对于这种日期时间选择器(我搜索其他人,它是相同的),在我看来,我必须使用"字符串"字段,如下所示:
<%= f.input :done_at, as: :string, input_html: { :data => { :behaviour => "datetimepicker" } } %>
Run Code Online (Sandbox Code Playgroud)
当我发布表单时,Rails负责处理时区并在数据库中存储UTC时间.
例如,我在该字段中输入"2014-03-14 19:45:07"(当地时间是巴黎,所以UTC +0100),我在数据库中有"2014-03-14 18:45:07" ,UTC.这是正确的.
但是当我想编辑信息时,Rails会在错误的时间内填写该字段.偏移时区丢失,我在字段中显示"2014-03-14 18:45:07"(UTC时间),因此在正确时间前1小时.
如何才能有正确的时间来处理用户时区?(不是UTC)
我尝试在http://jessehouse.com/blog/2013/11/15/working-with-timezones-and-ruby-on-rails/上找到的解决方案来覆盖日期的显示,但它不起作用.
def done_at
super.in_time_zone(time_zone) if super && time_zone
end
Run Code Online (Sandbox Code Playgroud)
如果在我看来,我把@ action.done_at,时间是正确的但不在现场.
谢谢,
弗雷德