标签: simple-form

rails simple_nested_form_for fields_for错误的参数数量

所以我正在使用rails 3.1构建一个表单

<%= simple_nested_form_for(@person, :url => collection_url, :html=>{:multipart => true}) do |f| %>
  <%= render :partial => "form", :locals => { :f => f } %>
<% end %>
Run Code Online (Sandbox Code Playgroud)

但部分中的这一行导致了问题:

<h2>Badges</h2> 
<ul id="certifications">
// this following line is raising the error "wrong number of arguments (4 for 3)"
<%= f.fields_for :certifications do |certification_form| %> 
    <%= render :partial => 'certification', :locals => { :f => certification_form } %>
<% end %>
</ul>
<%= f.link_to_add "Add a Badge", :certifications %>
Run Code Online (Sandbox Code Playgroud)

所以这是模型:

class …
Run Code Online (Sandbox Code Playgroud)

ruby-on-rails actionview nested-forms nested-attributes simple-form

8
推荐指数
2
解决办法
4166
查看次数

i18n使用simple_form标记嵌套模型

如果一个项目:

  • has_many:任务
  • accepts_nested_attributes_for:任务

我正在使用simple_form(简化):

simple_form_for @project do |f|
  f.input :project_name
  f.simple_fields_for :tasks do |j|
    j.input :task_name
  end
  f.submit
end
Run Code Online (Sandbox Code Playgroud)

我如何将标签国际化:task_name?我在我的simple_form.it.yml文件中尝试了很多组合,例如:

it:
  simple_form:
    labels:
      project:
        project_name: 'Nome progetto'
        task:
          task_name:  'Nome compito'
Run Code Online (Sandbox Code Playgroud)

无法在文档中找到示例.谷歌指出了几个明显相关的封闭问题:

https://github.com/plataformatec/simple_form/issues/48

https://github.com/plataformatec/simple_form/issues/194

但到目前为止,我感到茫然......

谢谢!朱塞佩

internationalization nested-attributes ruby-on-rails-3 simple-form

8
推荐指数
1
解决办法
6064
查看次数

如何将collection_check_boxes与数组一起使用?

所以我使用simple_form来构建表单,但这不是必需的.

我想要做的是使用simple_forms collection_check_boxes并传递一个数组.

我将我的标签存储在configatron中:

configatron.tags = [{:name => "wheels", :tagtype => "property"}, {:name => "roof", :tagtype => "property"}, {:name => "doors", :tagtype => "property"}]
Run Code Online (Sandbox Code Playgroud)

这是我的Tag模型:

class Tag
  include Mongoid::Document
  embedded_in :taggable, polymorphic: true

  field :name
  field :tagtype
end
Run Code Online (Sandbox Code Playgroud)

这是我尝试过的:

<%= f.collection_check_boxes :tags, @tags, @tags.map{|tag| tag.name}, @tags.map{|tag| tag.name} %>
Run Code Online (Sandbox Code Playgroud)

其中@tags被设置为configatron.tags在控制器

我只想让collection_check_boxes工作,然后在before_save上构建标记并将其嵌入当前资源中.

我已经读过某个地方,你可以映射到传入的集合中并选择该集合的项目内容.如果我做对了,请覆盖value_method?似乎无法记住你怎么能这样做.我还想传入此资源的当前标记,:collection => resource.tags以便在渲染时检查这些标记.

有没有办法做到这一点?我如何操纵form_builder使这成为可能,如果是这样,怎么样?我应该采取另一种方法吗?

旁注:此功能也应与骨干网一起使用,在某些地方,骨干网将用于添加标签.

tags ruby-on-rails ruby-on-rails-3 simple-form

8
推荐指数
2
解决办法
5754
查看次数

Rails:简单形式+引导程序 - 出错时,字段不变为红色

我已经开始使用Simple-form和Bootstrap了,我试图遵循这个引用:简单形式+ Bootstrap但我不知道发生了什么,因为当一个字段失败时,会发生以下情况:

没有正确的字段没有红色边框

关于这个截图我有一个问题:
1)如你所见,价格字段没有被红色包围.我怎样才能做到这一点?这是我的表单代码:

<%= simple_form_for @lesson, :html => { :class => 'well' } do |lesson_form| %>
<% if lesson_form.error_notification %>
    <div class="alert alert-error fade in">
      <a class="close" data-dismiss="alert" href="#">&times;</a>
      <%= lesson_form.error_notification %>
    </div>
<% end %>
  <%= lesson_form.input :title %>
  <%= lesson_form.input :category %>
  <%= lesson_form.input :description %>
  <%= lesson_form.input :price %>
  <%= lesson_form.button :submit, :label => 'Create', :class => 'btn btn-primary btn-large' %>
<% end -%>
Run Code Online (Sandbox Code Playgroud)

forms ruby-on-rails simple-form

8
推荐指数
1
解决办法
8658
查看次数

简单形式bootstrap水平和内联

我正在使用simple_form + bootstrap,但想知道是否有可能使某些字段以内联方式进行,而其他字段则以相同的形式进行.

我甚至可能希望将表单分成两列或更多列.

有没有办法通过包装器或可能通过不同的表单构建器或样式来实现这一点?

谢谢!

ruby-on-rails-3 simple-form twitter-bootstrap

8
推荐指数
1
解决办法
2万
查看次数

如何在form_for中使用select_year?

我的表格如下:

<%= form_for(@car, :html => {:class => 'form-horizontal' }) do |f| %>
  <% if @car.errors.any? %>
    <div id="error_explanation">
      <h2><%= pluralize(@car.errors.count, "error") %> prohibited this car from being saved</h2>
      <ul>
        <% @car.errors.full_messages.each do |msg| %>
          <li><%= msg %></li>
        <% end %>
      </ul>
    </div>
  <% end %>
  <div class="field">
    <%= f.label :price %><br />
    <%= f.text_field :price %>
  </div>

  <div class="field">
    <%= f.label :model_year %><br />
    <%  %>
  <% end %>
</div>
Run Code Online (Sandbox Code Playgroud)

我希望有一个集合选择从100年前开始的模型年份和未来的一年.我试过了

<%= f.select_year :model_year%>
Run Code Online (Sandbox Code Playgroud)

但它说select_year不是一个有效的方法.试着

<%= f.date :model_year, :discard_month => …
Run Code Online (Sandbox Code Playgroud)

ruby-on-rails date form-for simple-form

8
推荐指数
1
解决办法
5078
查看次数

simple_form集合包装器(无线电按钮):项目的双重封装

我想用simple_form重现这个单选按钮的单选按钮,以便使用http://semantic-ui.com/语法使simple_form工作:

  <div class="grouped inline fields">
    <div class="field">
      <div class="ui radio checkbox">
        <input type="radio" name="fruit" checked="">
        <label>Apples</label>
      </div>
    </div>
    <div class="field">
      <div class="ui radio checkbox">
        <input type="radio" name="fruit">
        <label>Oranges</label>
      </div>
    </div>
    <div class="field">
      <div class="ui radio checkbox">
        <input type="radio" name="fruit">
        <label>Pears</label>
      </div>
    </div>
    <div class="field">
      <div class="ui radio checkbox">
        <input type="radio" name="fruit">
        <label>Grapefruit</label>
      </div>
    </div>
  </div>
Run Code Online (Sandbox Code Playgroud)

所以我准备了一个自定义包装器:

config.wrappers :semantic_radios, tag: 'div', class: "grouped fields", error_class:   'error', hint_class: 'with_hint' do |b|
    b.use :html5
    b.use :label
    b.use :input
  end
Run Code Online (Sandbox Code Playgroud)

设置一些选项:

config.item_wrapper_tag …
Run Code Online (Sandbox Code Playgroud)

simple-form

8
推荐指数
2
解决办法
7418
查看次数

简单表格 - Rails 4 - 编辑

我正在尝试使用我的rails 4应用程序的简单表单.

我有一个项目模型,它有一个范围模型.范围属于项目.我有第三个模型,称为参与者,属于范围.Scope接受参与者的嵌套属性,项目接受范围的嵌套属性.

当我创建一个新项目时,我的表单有部分内容,这些部分是每个范围和参与者的嵌套表单.在我的范围表格中,我问这个项目是否涉及参与者.如果答案是真的,我使用JS表单助手来显示包含参与者表单的隐藏部分.

如果在创建项目后,我想编辑它,编辑功能会将我返回到项目表单,该表单显示参与者的复选框(如为true),但隐藏参与者表单.

我的问题是,如果选中参与者复选框为true,则应显示嵌套在项目表单中的参与者表单.我的JS表单助手隐藏了这个表单,直到选中该框为真,这在创建模式下工作正常,但我需要取消检查范围表单中的参与者框并重新检查它以显示参与者表单 - 这样我就可以编辑这些字段了.

如果在没有取消选中并重新检查表单的情况下询问参与的范围问题是真的,您知道如何透露参与者表格吗?

我的代码如下:

在我的JS表单助手中,我有(隐藏参与者嵌套表单,除非询问是否参与的范围问题是真的):

$(document).on 'change', '#' + inString +  '_scope_attributes_if_participant', ()->
  if $('#' + inString +  '_scope_attributes_if_participant').is(':checked')
    $('#participationrequest').show()
  else
    $('#participationrequest').hide()
Run Code Online (Sandbox Code Playgroud)

在我的范围表格中,我有:

    <%= s_all.input :if_participant, :as => :boolean, :label => false, inline_label: 'Public participants or volunteers' %>
Run Code Online (Sandbox Code Playgroud)

谢谢

javascript ruby-on-rails simple-form

8
推荐指数
1
解决办法
213
查看次数

基础6与Rails简单形式

简单表单包含Foundation 5模板.

但是,我无法在Web上找到为Foundation 6修改的任何模板文件.

生成的表单与Foundation 6的结合程度如何?此外,任何慷慨的基金会6模板或修改现有模板的提示?

ruby-on-rails simple-form zurb-foundation zurb-foundation-6

8
推荐指数
1
解决办法
943
查看次数

simple_form使用twitter引导程序使用<image>(X)标签呈现单选按钮组?

我试着用一段时间来使用simple_form来创建下面的例子但是+标签并修复了一些样式.任何人都知道如何解决:

  • 删除2的不知道它们来自哪里(似乎很奇怪i18n生产中的bug它会抛出一大堆I18n)
  • 在单选按钮后面有文字男性或女性

标签输出

结果来自以下代码:

     .clear
    = f.label "Gender"
    = f.collection_radio_buttons(:gender, [['Male', 'icon_male'], ['Female', 'icon_female']],
                                 :first, :last,
                                 :item_wrapper_class => 'horizontal',
                                 ) do |gender|
      = gender.label { image_tag("/assets/icons/16x16/#{gender.text}.png") + gender.radio_button  }

    .clear
    .ruler
Run Code Online (Sandbox Code Playgroud)

radio-button ruby-on-rails-3 simple-form twitter-bootstrap

7
推荐指数
3
解决办法
4780
查看次数