我的问题是如何设置只读的rails形式的字段.以下是引号控制器中的选择框.不允许用户更改选择.
<% @quote.test_items.each do |t| %>
<%= f.association :test_items, :label => false, :selected => t.id %>
<% end %>
Run Code Online (Sandbox Code Playgroud)
该应用程序使用simple_form.非常感谢.
我有两个模型,开发人员和任务,
class Developer < ActiveRecord::Base
attr_accessible :address, :comment, :email, :name, :nit, :phone, :web
has_many :assignments
has_many :tasks, :through => :assignments
end
class Task < ActiveRecord::Base
attr_accessible :description, :name, :sprint_id, :developer_ids
has_many :assignments
has_many :developers, :through => :assignments
end
class Assignment < ActiveRecord::Base
attr_accessible :accomplished_time, :developer_id, :estimated_time, :status, :task_id
belongs_to :task
belongs_to :developer
end
Run Code Online (Sandbox Code Playgroud)
我通过添加一个Assignment表来处理关系,所以我可以将许多开发人员添加到一个任务中,现在我也希望能够操作我添加到连接表中的其他字段,如'estimated_time',' completed_time'...等......我在Simple_form上得到的是`
<%= simple_form_for [@sprint,@task], :html => { :class => 'form-horizontal' } do |f| %>
<%= f.input :name %>
<%= f.input :description %>
<%= f.association :developers, :as …Run Code Online (Sandbox Code Playgroud) ruby-on-rails associations has-many-through ruby-on-rails-3 simple-form
我正在使用simple_form,我想知道在处理关联选择时是否可以跳过任何包装器div.
谢谢
我正在尝试在我的应用中为货币进行自定义输入.我有那些bootstrap包装等(我认为它带有simple_form或带有bootstrap gem ...),所以,我可以做类似的事情:
<%= f.input :cost, wrapper => :append do %>
<%= content_tag :span, "$", class: "add-on" %>
<%= f.number_field :cost %>
<% end %>
Run Code Online (Sandbox Code Playgroud)
它的工作方式与预期一致.问题是:我在很多地方需要同样的东西,而且我不想复制/粘贴它.
所以,我决定创建一个自定义输入.
到现在为止,我得到了以下代码:
class CurrencyInput < SimpleForm::Inputs::Base
def input
input_html_classes.unshift("string currency")
input_html_options[:type] ||= input_type if html5?
@builder.input attribute_name, :wrapper => :append do |b|
# content_tag(:span, "$", class: "add-on")
b.text_field(attribute_name, input_html_options)
end
end
end
Run Code Online (Sandbox Code Playgroud)
但是我遇到了一些错误.看起来b没有像预期的那样,所以,它只是不起作用.
真的可以这样做吗?我找不到任何例子,也不能让它自己工作.
提前致谢.
有没有人知道如何将类simple_form从'controls'改为'form-control'.这是Bootstrap 3中的一个更改.我知道config/initializers/simple_form.rb和config/initializers/simple_form_bootstrap.rb中有很多选项,但我找不到我需要的东西.
config.wrappers :bootstrap, :tag => 'div', :class => 'control-group', :error_ class => 'error' do |b|
b.use :html5
b.use :placeholder
b.use :label
b.wrapper :tag => 'div', :class => 'controls' do |ba|
ba.use :input
ba.use :error, :wrap_with => { :tag => 'span', :class => 'help-inline' }
ba.use :hint, :wrap_with => { :tag => 'p', :class => 'help-block' }
end
end
Run Code Online (Sandbox Code Playgroud)
在上面你可以将'control-group'替换为'form-group',但我认为没有办法改变输入标签的类.
ruby-on-rails simple-form twitter-bootstrap twitter-bootstrap-3
使用simple_form和Bootstrap时遇到问题3.关于输入的包装器标签.显示以下代码:
查看代码(带haml)
= simple_form_for @refer_email_form, url: create_refer_message_path, html: { class: "form-horizontal" } do |f|
= f.input :to, label_html: { class: "col-sm-2" }
= f.input :subject, label_html: { class: "col-sm-2" }
Run Code Online (Sandbox Code Playgroud)
配置/ simple_form_bootstrap.rb
SimpleForm.setup do |config|
config.input_class = "form-control"
config.wrappers :bootstrap, tag: 'div', class: 'form-group', error_class: 'error' do |b|
b.use :html5
b.use :placeholder
b.use :label, class: "control-label"
# b.wrapper tag: 'div', class: "col-sm-6" do |ba|
b.wrapper tag: 'div' do |ba|
ba.use :input
ba.use :error, wrap_with: { tag: 'span', class: 'help-inline' …Run Code Online (Sandbox Code Playgroud) 我有以下内容.
class Page < ActiveRecord::Base
belongs_to :category
serialize :fields
end
Run Code Online (Sandbox Code Playgroud)
价值fields将取决于类别.但作为一个例子;
{"address" => "8 finance street, hong kong",
"founded" => "1973"}
Run Code Online (Sandbox Code Playgroud)
在此示例中,类别已定义"address"并"founded"作为自定义字段.
我想要的是说;
= simple_form_for(@page) do |f|
= f.association :category
- f.object.category.fields.each do |field|
= f.input field.name
Run Code Online (Sandbox Code Playgroud)
但我需要做一些神奇的事情来处理@page.founded无效的事实
相反,我应该看看@page.fields["founded"].
有什么建议?
更新:
我有点接近了
- if f.object.category
- f.object.category.fields.each do |field|
= f.input field.name do
= text_field_tag "post[fields][#{field.name}]", f.object.fields[file.name]
Run Code Online (Sandbox Code Playgroud)
现在需要制作这个DRYer(不想指定对象的名称).
我会看看我是否可以为此编写一个像样的简单表单扩展.
我在rails中使用simple-form,我想知道是否有办法改变集合对象的显示方式.例如,我有类似的东西
<%= f.input :lang, :label => "Language", :collection => [ "en", "es, "zh", "fr" ] %>
Run Code Online (Sandbox Code Playgroud)
而不是显示为"en es zh"等,我希望它向用户显示为"英语西班牙语"等.反正有没有做那种事情?
提前致谢.
我正在使用RoR,我正在使用Simple_Form gem来表示我的表单.我有一个对象关系,用户可以有多个角色,在创建过程中,管理员可以选择要应用于新用户的角色.我希望Roles的左边是复选框,右边的名字是水平排列.
//"box"管理员//
而不是当前
//
"框"
管理员
//
我目前显示角色的代码是这样的.
<div class="control-group">
<%= f.label 'Roles' %>
<div class="controls">
<%= f.collection_check_boxes
:role_ids, Role.all, :id, :name %>
</div>
</div>
Run Code Online (Sandbox Code Playgroud)
我最感兴趣的部分是f.collection_check_boxes生成这样的代码.
<span>
<input blah blah />
<label class="collection_check_boxes" blah>blah</label>
</span>
Run Code Online (Sandbox Code Playgroud)
这让我很难在那里获得一个css类,因为有三个组件需要触及.我已经尝试将诸如虚拟类之类的东西添加到:html哈希,但是虚拟类甚至没有出现在渲染的html中.
任何帮助是极大的赞赏
编辑:解决方案
感谢Baldrick,我的工作erb看起来像这样.
<%= f.collection_check_boxes :role_ids, Role.all, :id, :name,
{:item_wrapper_class => 'checkbox_container'} %>
Run Code Online (Sandbox Code Playgroud)
我的CSS如下
.checkbox_container {
display: inline-block;
vertical-align: -1px;
margin: 5px;
}
.checkbox_container input {
display: inline;
}
.checkbox_container .collection_check_boxes{
display: inline;
vertical-align: -5px;
}
Run Code Online (Sandbox Code Playgroud) 我想在Rails 4中创建一个应用程序.
我正在使用简单的表单形式,并且刚刚尝试使用gem'inpendent-fields-rails'来隐藏或显示基于主要问题的表单字段的子集问题.
我卡住了.
我已将gems添加到我的gem文件中:
gem 'dependent-fields-rails'
gem 'underscore-rails'
Run Code Online (Sandbox Code Playgroud)
我已将我的application.js更新为:
//= require dependent-fields
//= require underscore
Run Code Online (Sandbox Code Playgroud)
我的表格有:
<%= f.simple_fields_for :project_date do |pdf| %>
<%= pdf.error_notification %>
<div class="form-inputs">
<%= pdf.input :student_project, as: :radio_buttons, :label => "Is this a project in which students may participate?", autofocus: true %>
<div class="js-dependent-fields" data-radio-name="project_date[student_project]" data-radio-value="true">
<%= pdf.input :course_project, as: :radio_buttons, :label => "Is this a project students complete for credit towards course assessment?" %>
<%= pdf.input :recurring_project, as: :radio_buttons, :label => "Is this project …Run Code Online (Sandbox Code Playgroud)