这个输入:
<%= f.input :keywords, label: false, :input_html => {:class => "span8"}, :placeholder => "Park Slope, Prospect Heights, Fort Green..." %>
Run Code Online (Sandbox Code Playgroud)
产生这个:
<div class="control-group string optional">
<div class="controls">
<input class="string optional span8" id="search_keywords" name="search[keywords]" placeholder="Park Slope, Prospect Heights, Fort Green..." size="50" type="text" />
</div>
</div>
Run Code Online (Sandbox Code Playgroud)
如何在input没有div的情况下单独生成?
谢谢.
我正在使用simple_form gem并生成我正在指定remote:true选项的表单,如下所示:
<%= simple_form_for @webinar, validate: true, remote:true do |f| %>
Run Code Online (Sandbox Code Playgroud)
因此,表单的输出html是以下片段:
<form accept-charset="UTF-8" action="/webinars" class="simple_form new_webinar" data-remote="true" data-validate="true" enctype="multipart/form-data" id="new_webinar" method="post" novalidate="novalidate"> ... </form>
Run Code Online (Sandbox Code Playgroud)
在我检查时,使用标准的form_for帮助器是在使用remote:true选项时将data-remote ='true'添加到表单中.正如你从生成的html中看到的那样,当我使用simple_form gem时,也有这样的属性.
所以,在我的控制器中,我有:
def create
@webinar = Webinar.new(params[:webinar])
respond_to do |format|
if @webinar.save
format.html { redirect_to @webinar, notice: 'Webinar was successfully created.' }
format.js
format.json { render json: @webinar, status: :created, location: @webinar }
else
format.html { render action: "new" }
format.json { render json: @webinar.errors, status: :unprocessable_entity …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用FontAwesome制作带有无线电收集的星级评级表,为此我实际上需要更改simple_form生成的collection_radio_button输入的标签类,但找不到任何明显的解决方案.
到目前为止我使用:
form_for @user do |f|
f.collection_radio_buttons :rating, [[1, 'Bad'] ,[2, 'Ok'], [3, 'Great']],
:first, :last, { item_wrapper_tag: false }
end
Run Code Online (Sandbox Code Playgroud)
哪个产生:
<input id="review_rating_1" name="review[rating]" type="radio" value="1" />
<label class="collection_radio_buttons" for="review_rating_1">Bad</label>
<input id="review_rating_2" name="review[rating]" type="radio" value="2" />
<label class="collection_radio_buttons" for="review_rating_2">Ok</label>
<input id="review_rating_3" name="user[options]" type="radio" value="3" />
<label class="collection_radio_buttons" for="review_rating_3">Great</label>
Run Code Online (Sandbox Code Playgroud)
但我希望标签有一个额外的类,如:
<input id="review_rating_3" name="user[options]" type="radio" value="3" />
<label class="collection_radio_buttons icon-star" for="review_rating_3">Great</label>
Run Code Online (Sandbox Code Playgroud)
更新:此类在静态定义:https://github.com/plataformatec/simple_form/blob/master/lib/simple_form/tags.rb#L43
是否有整合的好方法hstore有simple_form?
我只是找不到实现这个目标的方法.我有一个调用的列widget_locations,我想将:left_area1, :mid_area1, :left_area2, :mid_area2, :right_area2键和值存储为嵌套的哈希,所以它们如下所示:
{:left_area1 => {:video_id => 1, :presentation_id => 3}, :mid_area1 => {:chat_id => 1, :presentation_id => 5}, :left_area2, :mid_area2, :right_area2}
Run Code Online (Sandbox Code Playgroud)
有没有一种在simple_form中实现这一目标的最佳方法?
我有albums,pictures在哪里albums hasmany pictures
这是我的routes.rb
resources :albums do
resources :photos
end
Run Code Online (Sandbox Code Playgroud)
而不是photos_path我的路径是album_photos_path
在my photos/new.html.erb我得到这个错误:
undefined method photos_path' for #<#<Class:0x5232b40>:0x3cd55a0>
我怎么做而不是photos_path简单的形式写album_photos_path?
我的new.html.erb
<%= simple_form_for([@album, @photo]) do |f| %>
<%= f.error_notification %>
<div class="form-inputs">
<%= f.input :title %>
<%= f.input :description %>
</div>
<div class="form-actions">
<%= f.button :submit %>
</div>
<% end %>
Run Code Online (Sandbox Code Playgroud) 我在simple_form中有一个基本的文本输入:
= f.input :title, label: "Name:", placeholder: "New make"
Run Code Online (Sandbox Code Playgroud)
我在尝试渲染视图时获取此异常:
No input found for citext
Run Code Online (Sandbox Code Playgroud)
我该如何解决?
我正在创建一个使用Ruby/Rails/HAML存储卡的系统 - 在这种情况下,有一个Card类有很多颜色(这也是一个类).在创建和编辑卡片时,我正在使用Cocoon gem来动态添加颜色关联.
我遇到的问题是,在卡片型号中,卡片最多只能有5种颜色.然而,界面允许添加无限的颜色,从而导致错误.
在Cocoon中是否有办法限制可以添加到表单的关联数量,以便不超过此限制?
这是添加/编辑卡片的表单代码
= simple_form_for @card, multipart: true do |c|
= c.input :name, label: "Name of the card"
= c.input :cost, label: "Cost of the card"
#colours
= c.simple_fields_for :colours do |colour|
= render "colour_fields", f: colour
.links
= link_to_add_association 'add colour', c, :colours
Run Code Online (Sandbox Code Playgroud)
这是colour_fields形式
.nested-fields
= f.input :value, as: :select, collection: Colour::VALUES, selected: f.object.value, include_blank: false
= link_to_remove_association "remove colour", f
Run Code Online (Sandbox Code Playgroud)
提前致谢.
在使用Simple_form_for时,在我的数字字段中,使用Google Chrome时,字段旁边会显示滚动条.
我怎么能阻止他们出现?

我无法从简单的表单更改默认错误消息,我试图编辑简单的表单区域设置文件,但它似乎被忽略
这是我的语言环境文件:
#config/locales/simple_form.en.yml
en:
simple_form:
error_notification:
default_message: "A custom message:"
Run Code Online (Sandbox Code Playgroud)
但我仍然得到"请回顾下面的问题:"
有谁知道我做错了什么?
如何使一个简单的布尔复选框默认为true?
assign_client 是一个布尔字段.
我试过这些:
<%= f.input :assign_client, :label => 'Charge Client?', :true %>
<%= f.input :assign_client, :label => 'Charge Client?', :value => :true %>
<%= f.input :assign_client, :label => 'Charge Client?', :value => 1 %>
Run Code Online (Sandbox Code Playgroud)
谢谢您的帮助!