date我的数据库中有一个类型字段.
这是我正在使用的视图代码:
# Using 'as: :string' to avoid those three dropdowns rails generates.
= f.input_field :start_date, as: :string, class: 'form-control datepicker'
Run Code Online (Sandbox Code Playgroud)
保存日期时,我使用一个显示日历的jquery插件,并写入如下日期:11/05/2013.
但是,在编辑同一记录时,输入会填充一个值2013-05-11.
我怎样才能使它如此simple_form实际上尊重我定义的日期格式en.yml?
我正在尝试使用Rails和Simple Form创建一个带有country-select的应用程序.
我收到的错误是:
wrong number of arguments (4 for 0)
Run Code Online (Sandbox Code Playgroud)
我正在使用我找到的示例,在国家选择gem文档页面上的简单表单.我不明白出了什么问题.
在我的模型中,我有:
geocoded_by :address
after_validation :geocode, if: ->(obj){ @obj.address.present? and @obj.address_changed? }
def address
[city, state, participation_country].compact.join(', ')
end
Run Code Online (Sandbox Code Playgroud)
在我的表格中,我有:
<%= f.simple_fields_for :scope do |participants_s| %>
<%= participants_s.simple_fields_for :participant do |par| %>
<%= par.select :participation_country,
priority: ["AU", "GB", "NZ", "US"],
selected: :participation_country,
label: false,
prompt: "Select participation country" %>
Run Code Online (Sandbox Code Playgroud)
我使用时遇到同样的错误
<%= par.input :participation_country,
Run Code Online (Sandbox Code Playgroud)
在我看来,我有:
<%= @project.scope.participant.address %>
Run Code Online (Sandbox Code Playgroud)
在试图设置时,有谁能看到我做错了什么?错误消息表明有问题的行是:
<%= par.select :participation_country,
Run Code Online (Sandbox Code Playgroud)
除了建议的国家/地区代码,我无法计算4个,但我删除了其中一个尝试,但我得到了相同的错误.
当我尝试:
<%= par.country_select("participation_country", {:prompt => "Choose Country"})%>
Run Code Online (Sandbox Code Playgroud)
我得到了同样的错误:错误的参数数量(4表示0) …
我在模型上有错误而不是模型字段,所以这些错误被添加到错误[:base]中.在我使用的简单表单代码中;
<%= f.error_notification %>
Run Code Online (Sandbox Code Playgroud)
这显示了普通错误,但没有显示基本错误.如何查看基本错误?
我有一个Flight嵌套在FlightLog模型中的模型.A FlightLog可能包含许多航班.
我正在使用SimpleForm和bootstrap安装,这使得在验证失败时可以包含错误类错误的表单元素.
问题是,即使为嵌套模型触发了验证,simple_fields_for中有错误的字段也没有被标记,因此无法确定哪个属性无效.
在调用create action时检查错误哈希后,我可以看到它正确填充了顶层的错误,以及每个资源中嵌套资源的错误.
如何修改simple_form的行为以将errors类添加到每个嵌套模型的控件组以匹配父行为?
提前致谢.

我使用simple_form和多部分上传不起作用(上传单个文件工作).Rails file_field_tag工作......
Rails 3.2.13
<%= simple_form_for @building, input_html: {multipart: true} do |f| %>
...
<%= f.simple_fields_for :paintings do |p| %>
<%= p.input :image, as: :file %>
<% end %>
<% end %>
Run Code Online (Sandbox Code Playgroud) 我在我的rails应用程序中使用了Simple_Form和Zurb Foundation.
一个或多个视图的表单具有以下date_select
表单字段显示堆叠而不是内联.我已经检查了所有内容,无法弄清楚如何正确显示这些内容.
我错过了什么?您可以 在event.html.erb视图中看到https://github.com/stanrails/momtomom上的回购.
该部分的代码如下:
<div class="row">
<div class="small-5 columns">
<%= f.date_select :eventDate %>
</div>
</div>
Run Code Online (Sandbox Code Playgroud) 我只是卸载simple_form
gem uninstall simple_form
Run Code Online (Sandbox Code Playgroud)
并删除Gemfile /相关文件中的simple_form,如simple_form.en.yml.
现在,如果我的应用验证失败,则会出现以下错误
I18n::InvalidLocaleData - can not load translations from
.../config/locales/simple_form.en.yml: #<Errno::ENOENT:
No such file or directory @ rb_sysopen - .../config/locales/simple_form.en.yml>:
Run Code Online (Sandbox Code Playgroud)
之前我没有设置任何i18n,是否有任何与simple_form相关的设置我还要修改?
任何想法都表示赞赏!
我声明一个enum类型如下的模型:
class Event < ActiveRecord::Base
enum event_type: { "special_event" => 0,
"pto" => 1,
"hospitality" => 2,
"classroom" => 3
}
Run Code Online (Sandbox Code Playgroud)
然后在我的更新视图中,我有一个表单:
<%= simple_form_for @event do |f| %>
<%= f.input :event_type, collection: Event.event_types.keys %>
...
<% end %>
Run Code Online (Sandbox Code Playgroud)
这很好用,我得到一个填充了我的枚举类型的选择.当我@event.update(event_params)在我的控制器中执行时,我可以检查数据库并看到该event_type字段已更新为正确的整数值.
但是,当我再次访问编辑页面时,select会显示一个nil值.如果我通过在表单中添加调试行来检查其值:
<%= f.input :event_type, collection: Event.event_types.keys %>
<%= debug @event %>
Run Code Online (Sandbox Code Playgroud)
我看到值event_type是正确的:
--- !ruby/object:Event
attributes:
...
event_type: '2'
Run Code Online (Sandbox Code Playgroud)
但输入选择器仍然是空白而不是应该显示"好客".
任何想法将不胜感激.:)
给定模型Albumhas_many Song,后者使用本地化字段,例如:
Song#name_en
Song#description_en
Song#name_fr
Song#description_fr
[...]
Run Code Online (Sandbox Code Playgroud)
由于前端设计,我无法f.simple_fields_for :songs在一个地方为所有歌曲属性做一个,但需要拆分它:
= f.simple_fields_for :songs do
= render partial: 'song_en_fields', locals: { f: f, locale: :en }
[...]
= f.simple_fields_for :songs do
= render partial: 'song_fields', locals: { f: f, locale: :fr }
[...]
Run Code Online (Sandbox Code Playgroud)
得到的字段建立索引用[0],[1]等他们应该,但是,指数不为0的每个indvidivual重新启动simple_fields_for,但只是保持计数.
我检查了源代码并index在Rails中找到了一个选项fields_for,但这只是添加了一个额外的索引数组.
有没有办法在同一集合多次调用simple_fields_for(或fields_for)时"重置"索引的自动增量?
我正在编辑资源 - @article- 每当我提交它时,我都会收到以下错误:
JSON::ParserError in ArticlesController#update
783: unexpected token at '#<ImageUploader::UploadedFile:0x00007fb154adb508>'
Run Code Online (Sandbox Code Playgroud)
它突出显示了这一行:
if @article.update(article_params)
Run Code Online (Sandbox Code Playgroud)
这是我的Article#Update操作中的正常 Rails 样板代码:
def update
respond_to do |format|
if @article.update(article_params)
format.html { redirect_to @article, notice: 'Article was successfully updated.' }
format.json { render :show, status: :ok, location: @article }
else
format.html { render :edit }
format.json { render json: @article.errors, status: :unprocessable_entity }
end
end
end
Run Code Online (Sandbox Code Playgroud)
这是服务器日志的完整输出(包括参数):
Started PATCH "/articles/welcome-to-ftja" for ::1 at 2020-05-04 02:11:43 -0500
Processing by ArticlesController#update as HTML
Parameters: …Run Code Online (Sandbox Code Playgroud) simple-form ×10
ruby ×2
date ×1
enums ×1
fields-for ×1
html ×1
input ×1
json ×1
rails-i18n ×1
ruby-2.7 ×1
trix ×1
validation ×1