我不知道为什么它不像示例那样重复.当我把以下代码用于这个表单时:
<%= simple_form_for(resource, :as => resource_name, :url => registration_path(resource_name), :html => { :class => "form-horizontal" } ) do |f| %>
<%= f.input :user_name, :input_html => { :class => "span3" }, :hint => "just letters and numbers please." %>
<% end %>
Run Code Online (Sandbox Code Playgroud)
现在它看起来像这样:

当我希望它像这样(这里的第一个例子:http://simple-form-bootstrap.plataformatec.com.br/articles/new).

问题在于生成的HTML.我的HTML是:
<div class="input string optional">
<label for="user_user_name" class="string optional"> User name</label>
<input type="text" size="50" name="user[user_name]" maxlength="25" id="user_user_name" class="string optional span3">
<span class="hint">no spaces or special characters, just letters and numbers please</span>
</div>
Run Code Online (Sandbox Code Playgroud)
和Simple_forms …
我在注册表单上遇到问题.它是使用SimpleForm创建的,使用Devise进行身份验证.提交表单时,如果电子邮件或密码为空,则会显示两次错误.在用户模型中,存在对名字,姓氏,配置文件名称,密码和电子邮件的存在验证.这些重复错误仅显示在空白电子邮件和密码字段中.任何其他空白字段都会这样说一次.
例:
#错误禁止此用户被保存:
- 电子邮件不能为空
- 电子邮件不能为空
- 密码不能为空
- 密码不能为空
user.rb:
class User < ActiveRecord::Base
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable
attr_accessible :email, :password, :password_confirmation, :remember_me, :first_name, :last_name, :profile_name
validates :first_name, :last_name, :email, :profile_name, :password, presence: true
validates :profile_name, uniqueness: true,
format: {
with: /^[a-zA-Z0-9_-]+$/
}
has_many :posts
def full_name
first_name + " " + last_name
end
end
Run Code Online (Sandbox Code Playgroud)
注册/ new.html.erb:
<%= simple_form_for(resource, :as => resource_name, :url => registration_path(resource_name)) do |f| %>
<%= devise_error_messages! %>
<div class="formGroupLeft">
<%= f.input :first_name, :input_html => { …Run Code Online (Sandbox Code Playgroud) 我在一个Rails 4应用程序中使用Simple Form作为@user对象并拥有该行...
= f.input :entity_name
这会name='user[entity_name]'在input标记内生成HTML .我想改变它,因为我在控制器中做了一些自定义处理,但还没有找到办法.
我已经尝试将线路更改为......
= f.input :entity_name, name: 'entity[name]'
Run Code Online (Sandbox Code Playgroud)
...但这似乎根本不会影响生成的HTML.到目前为止,我还没有在Google/Stack Overflow上找到任何有此问题的人.
有没有人知道是否/如何通过Simple Form帮助器更改name属性?
提前致谢!
这是一个简单的问题,我有点惭愧地问,但是我一直在撞墙并在导轨3文档中导航而没有任何成功:/
所以,这是事情:
当我使用fields_for帮助程序时,它将生成的字段包装在<div class="fields"> ... </div>标记中.
所以,我的代码是
<ul class="block-grid two-up">
<%= f.fields_for :images do |image_builder| %>
<%= render "images/form", :f => image_builder %>
<% end %>
</ul>
Run Code Online (Sandbox Code Playgroud)
生成的html是:
<ul class="block-grid two-up">
<div class="fields">
<div>
<label for="company_images_attributes_0_image"> Image</label>
<input id="company_images_attributes_0_image"
name="company[images_attributes][0][image]" type="file">
</div>
</div>
<div class="fields">
<div>
<label for="company_images_attributes_1_image"> Image</label>
<input id="company_images_attributes_1_image"
name="company[images_attributes][1][image]" type="file">
</div>
</div>
</ul>
Run Code Online (Sandbox Code Playgroud)
我想要做的是将<div class="fields">包装器标签更改为<li>.
文档说您可以将选项传递给fields_for,但是不清楚您可以传递哪些选项,也许您可以更改此包装器标记?
可能是覆盖一个函数,有点像ActionView::Base.field_error_proc表单中的错误.
快速编辑:我忘了提到我正在使用simple_form生成此表单.我尝试在simple_form.rb配置文件中查找自定义方法,但我没有看到任何方法.
解决方案 经过进一步调查后,结果表明表单也使用了nested_form gem来生成表单(不仅仅是simple_form).这个生成器导致fields_for被包装在div标签中.谢谢大家的建议!
在http://simple-form.plataformatec.com.br/#usage/collections的 simple_form 2.0中,似乎只有一些关于grouped_select功能的文档.文档提供了以下内容:
f.input :country_id, :collection => @continents, :as => :grouped_select, :group_method => :countries
Run Code Online (Sandbox Code Playgroud)
但这似乎并没有给我足够的背景来使其发挥作用.这就是我所拥有的.
我有三种模式:查询,广告和插入
广告has_many插入和插入belongs_to广告查询belongs_to插入和插入has_many查询
此下拉列表用于查询视图.使用simple_form我可以= f.input :insertion, :collection => @ads至少在下拉列表中输出广告标题列表.我希望ad.title可以作为optgroup.然后我想将广告插入作为可选择的内容...所以类似于:
<select>
<optgroup label="Ad.Title">
<option value="Ad.Insertion.id">Ad.Insertion.Title</option>
<option value="Ad.Insertion.id">Ad.Insertion.Title</option>
<option value="Ad.Insertion.id">Ad.Insertion.Title</option>
<option value="Ad.Insertion.id">Ad.Insertion.Title</option>
</optgroup>
<optgroup label="Ad.Title">
<option value="Ad.Insertion.id">Ad.Insertion.Title</option>
<option value="Ad.Insertion.id">Ad.Insertion.Title</option>
<option value="Ad.Insertion.id">Ad.Insertion.Title</option>
<option value="Ad.Insertion.id">Ad.Insertion.Title</option>
</optgroup>
</select>
Run Code Online (Sandbox Code Playgroud)
任何人都可以提供有关使这个simple_form功能有效的建议吗?我真的很感激!
如果您对如何执行此属性有所了解,请告诉我是否可以告诉您有关该应用程序的任何其他信息.
提前致谢!
更新:我已经能够使用以下部分工作:
= f.input(:insertion_id, :collection => Ad.order(:name), :as => :grouped_select, :group_method => :insertions)
Run Code Online (Sandbox Code Playgroud)
这个问题是没有办法从我能说的内容中指定用作显示文本的列.我欢迎任何意见.
我有一个显示一组输入的表单.我也有一个按钮,当点击时,我发出一个ajax请求,它应该用一组不同的输入替换现有的输入.
我所有的ajaxy链接东西都很好.问题是我正在使用a form_for,所以为了显示新的表单输入,我需要表单构建器实例.
<%= simple_form_for @order do |f| %>
<div id="info">
<%= render 'my_first_form_fields_partial', f: f %>
</div>
<%= link_to 'Change inputs', change_inputs_path, remote: true %>
<% end %>
Run Code Online (Sandbox Code Playgroud)
我希望我的js.erb看起来像这样,但f只在视图中的窗体范围内定义.
$('#info').html("<%= escape_javascript(render 'my_second_fields_partial', f: f) %>");
Run Code Online (Sandbox Code Playgroud)
我怎样才能使它能够f以某种方式进入那个部分呢?
ajax ruby-on-rails partial-views ruby-on-rails-3 simple-form
<p><%= f.input :terms, :as => :boolean, :label => false, :boolean_style => :inline %>
Accept <%= link_to "Terms of use", terms_path,:remote => true %>
and <%=link_to "privacy Policy", privacy_path, :remote => true%></p>
Run Code Online (Sandbox Code Playgroud)
它最终看起来像这样

在同一条线上排列它们的最佳方法是什么.
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?
我有这个调用datepicker的表单:
...
<%= f.input :expiration_date, as: :datepicker, required: false %>
...
Run Code Online (Sandbox Code Playgroud)
Simple_form包装器: app/inputs/datepicker_input.rb
class DatepickerInput < SimpleForm::Inputs::Base
def input
@builder.text_field(attribute_name, input_html_options) + \
@builder.hidden_field(attribute_name, { :class => attribute_name.to_s + "-alt"})
end
end
Run Code Online (Sandbox Code Playgroud)
从头开始加载页面($(document).ready event)时,会生成以下html:
<input class="datepicker optional form-control hasDatepicker" id="order_expiration_date" name="order[expiration_date]" type="text">
Run Code Online (Sandbox Code Playgroud)
但是,当页面加载turbolinks时(从侧面导航栏,"page:load"事件),呈现的HTML如下:
<input class="datepicker optional form-control" id="order_expiration_date" name="order[expiration_date]" type="text">
Run Code Online (Sandbox Code Playgroud)
当然,我可以简单地在.html.erb或application.js文件中添加hasDatepicker类,但我想知道是否可以使用Rails功能实现它.
datepicker jquery-ui-datepicker simple-form turbolinks ruby-on-rails-4
我正在尝试实现嵌套模型,这里是路由文件条目:
resources :projects do
resources :instances
end
Run Code Online (Sandbox Code Playgroud)
以下是项目控制器的片段:
# GET /projects/new
def new
@project = Project.new
@project.instances.build
end
Run Code Online (Sandbox Code Playgroud)
和项目的表单视图:
<%= simple_form_for(@project) do |f| %>
...
<%= label_tag :instance_count, "Instance Count" %>
<%= select_tag :instance_count, options_for_select([0, 1, 2, 3, 4, 5], 0) %>
...
<% end %>
Run Code Online (Sandbox Code Playgroud)
现在,当我更改实例计数时,我需要在上面的表单下面多次显示实例字段.这是部分代码:
<%= form.simple_fields_for :instances do |i| %>
...
<% end %>
Run Code Online (Sandbox Code Playgroud)
基本上我需要<%= render 'instances/form', form: f %>从项目的javascript文件中调用.它应该像链接remote: true选项一样工作.但在这种情况下没有链接,但在更改事件时需要显示表单.我该如何实现呢?
simple-form ×10
html ×3
ajax ×1
css ×1
date ×1
datepicker ×1
devise ×1
fields-for ×1
forms ×1
input ×1
javascript ×1
optgroup ×1
ruby ×1
turbolinks ×1
validation ×1