我开始将simple_form用于rails应用程序,并且在转换我的一些表单时,我遇到了一个有两个模型正在使用的模式,它是一种嵌入式表单.这可以用simple_form吗?
<% simple_form_for :topic, :url => forum_topics_path do |t| %>
<%= t.input :name, :label => 'Topic' %></p>
<p>First Post:<br/></p>
Title: <%= text_field :post, :title %> <--- this is where i start having problems
Body: <%= text_area :post, :body %>
<%= t.submit 'Save' %>
Run Code Online (Sandbox Code Playgroud)
谢谢
无论我做什么,我的朋友的嵌套表单字段都不会显示..我相信,accept_nested_attributes设置是否正确?
views/user_steps/show.html.erb
<%= simple_form_for @user do |f| %>
<%= f.input :city %>
<%= f.input :address %>
<%= f.input :zipcode %>
<%= f.input :date_of_birth %>
<%= f.input :gender, :collection => ['male','female'] %>
<%= f.association :interests, :as => :check_boxes, :label => false %>
<%= f.association :holidays, :as => :check_boxes, :label => false %>
<%= f.simple_fields_for :friends do |friend_f| %>
<%= friend_f.input :name %>
<%= friend_f.input :dob %>
<%= friend_f.input :gender %>
<% end %>
<%= f.button :submit %>
<%end%>
class UserStepsController < …Run Code Online (Sandbox Code Playgroud) ruby-on-rails associations nested-attributes ruby-on-rails-3 simple-form
我正在使用简单的形式宝石,我想知道你如何做collection_select?我知道你可以做一个选择,但是如何从集合中获取值?
那么,例如,您将如何以简单的形式执行此操作:
collection_select(:post, :author_id, Author.all, :id, :name_with_initial, :prompt => true)
Run Code Online (Sandbox Code Playgroud)
谢谢
How would one set:id =>"myvalue"用于simpleform 集合输入字段?或者在旁注,我也试图设置age_from的ID,如id =>"age_from"无法弄清楚如何做到这两者,似乎非常缺乏这些文档.
尝试了我可以提出的所有可能的组合:
= f.input_field :age_to,
:label => "Age from",
:collection => 18..60,
:select => 19 <------- set this to '19' for this collection?
:style => "width: 50px !important",
:id => "myid" <------- how to set id for this collection?
Run Code Online (Sandbox Code Playgroud) 我有这个选择与simple_form:
<%= f.input :theme, :collection => ["#{t('.text_1')}", "#{t('.text_2')}", "#{t('.text_3')}", "#{t('.text_4')}", :value_method => lambda { |n| n } %>
Run Code Online (Sandbox Code Playgroud)
html是:
<select class="select required" id="inquiry_theme" name="inquiry[theme]"><option value="">Choose a topic related to your query</option>
<option value="Text1">Text1</option>
<option value="Text2">Text2</option>
<option value="Text3">Text3</option>
<option value="Text4">Text4</option>
Run Code Online (Sandbox Code Playgroud)
我想用一个范围数字来设置值而不是文本,例如:
<select class="select required" id="inquiry_theme" name="inquiry[theme]"><option value="">Choose a topic related to your query</option>
<option value="1">Text1</option>
<option value="2">Text2</option>
<option value="3">Text3</option>
<option value="4">Text4</option>
Run Code Online (Sandbox Code Playgroud)
可以使用lambda :value_method吗?
谢谢!
ruby ruby-on-rails ruby-on-rails-3 simple-form ruby-on-rails-3.1
我知道这是一项艰巨的任务,但是当用户导航到不同的页面而没有提交时,是否有任何保存表单输入的好方法,所以当他们回来时他们不必重新输入信息?
我正在使用Rails 4,Simple Form和jQuery,但我对任何不是丑陋的黑客的解决方案持开放态度.
我一直在尝试构建一个搜索表单,允许用户通过选择下拉列表中的多个复选框选项进行搜索.问题是,当我提交表单时,值会在一个数组中传递,最后一个空值,当我检查日志时查询看起来像这样
UPDATE `searches` SET `ethnicity` = '---\n- Pacific Islander\n- White\n- Other\n- \'\'\n', `updated_at` = '2014-04-21 18:24:03' WHERE `searches`.`id` = 1
Run Code Online (Sandbox Code Playgroud)
我不明白为什么我在每个表单值周围都有额外的字符.我使用简单表格,我的表格看起来像这样
<%= simple_form_for(:search, :url => {:controller => 'searches', :action => 'update', :slug => session[:username]}) do |f| %>
<%= f.error_notification %>
<%= f.input :ethnicity, :label => "Ethnicity", :collection => ["Asian","Black", "Hispanic/Latino", "Indian", "Middle Eastern", "Native American", "Pacific Islander", "White", "Other"], :include_blank => "Anything", wrapper_html: { class: 'form-group' }, :as => :check_boxes, :input_html => {:name => "search[ethnicity][]", :multiple => true}, include_hidden: false …Run Code Online (Sandbox Code Playgroud) 我有以下Ruby:
<%= simple_form_for @answer, url: presentation_survey_path(@presentation) do |f| %>
<%= f.collection_radio_buttons :option_id, @question.options_array, :first, :last, {label: false} do |b| %>
<div class="col-sm-4">
<%= b.label(class: 'btn btn-large', style: 'margin-right: 20px; margin-left: 20px;') {b.radio_button(id: b.object.last, class: 'answer-input', style: 'display: none;') + b.text } %>
</div>
<% end %>
Run Code Online (Sandbox Code Playgroud)
它正确生成html,除了它生成两个标签:
<span>
<label for="answer_option_id_15">
<div class="col-sm-4">
<label class="btn btn-large" for="answer_option_id_15" style="margin-right: 20px; margin-left: 20px;">
<input class="answer-input" id="Way too many" name="answer[option_id]" style="display: none;" type="radio" value="15" />
Way too many
</label>
</div>
</label>
</span>
Run Code Online (Sandbox Code Playgroud)
由于某种原因,它正在制造第一个标签.我只想保留第二个.标签:false不起作用.如何摆脱第一个标签?
ruby ruby-on-rails simple-form ruby-on-rails-4 simple-form-for
我有一个问题是使用simple_form在我的视图中创建工作选择枚举字段
这是我的代码:
# In model project.rb
enum status: [:draft, :published]
# In view _form.html.erb
<%= simple_form_for @project do |f| %>
<%= f.input :title %>
<%= f.input :status %>
...
<% end %>
Run Code Online (Sandbox Code Playgroud)
这是输出HTML5数字(整数增量)字段而不是选择.
如果我改为:
...
<%= f.input :status, as: :select %>
or
<%= f.input :status, as: :radio_buttons %>
...
Run Code Online (Sandbox Code Playgroud)
它输出一个选择列表/单选按钮,标签为"是"和"否".当我尝试保存时,我得到#{integer}不是有效值错误.
任何帮助,将不胜感激.
我正在为简单形式编写自定义包装:
## Inputs
b.wrapper tag: :div, class: 'col-lg-4 input-group' do |component|
component.use :input, class: 'form-control'
component.wrapper tag: :span, class: 'input-group-addon' do |icon|
icon.wrapper :icon, tag: :i do
end
end
end
Run Code Online (Sandbox Code Playgroud)
生成HTML:
<div class="string optional q_post_date_gteq">
<div class="col-lg-4 input-group">
<input class="string optional datepicker form-control" placeholder="Start" type="text" name="q[post_date_gteq]" id="q_post_date_gteq">
<span class="input-group-addon"><i class="icon-calendar"></i></span>
</div>
</div>
Run Code Online (Sandbox Code Playgroud)
在<div class="string optional q_post_date_gteq">似乎是自动生成。我想给它添加一个类,这怎么可能?
ruby-on-rails ×10
simple-form ×10
forms ×2
ruby ×2
ajax ×1
associations ×1
enums ×1
jquery ×1
mysql ×1