0

* 编辑 *

我正在使用 Foundation 主题,我相信问题出在其中。我创建了一个新的基本应用程序,在添加主题之前没有任何问题。当我找到罪魁祸首时,我会更新这个。

*以前的编辑*

我想消除场景中的一些变量,所以我使用 form_for 而不是 simple_form_for 对此进行了测试,但没有成功。

在 Cocoon 的文档中,它提到了较新版本的 Bootstrap 的 :wrapper => 'bootstrap' 选项,我确实使用了 simple_form 提供的类似基础包装器,但没有成功。

= simple_form_for @group, :wrapper => 'foundation', :html => {:class => 'form-vertical' } do |f|
...
= f.simple_fields_for :solicitations do |solicitation|
  = render 'solicitation_fields', :f => solicitation
.links
  = link_to_add_association "Add Invitation?", f, :solicitations, :render_options => { :wrapper => 'foundation' }

如果这是一个因素,我删除了大部分样式。它不是。

FWIW,我正在使用 Rails 站点上推荐的 Ruby 2.1。另外,我因过度撞击墙壁而头疼。

底线问题:为什么显示部分的触发器不起作用?

*结束编辑*

我非常想使用 Nathanvda 的 Cocoon gem,但在单击 link_to_add_to_association 后无法显示关联的嵌套表单。确实会出现确认消息。我似乎遗漏了一些东西,或者我对 simple_form、zurb 和 cocoon 的使用使解决方案复杂化。

  • 导轨 4.0.2
  • simple_form 3.0.1
  • zurb-基础 4.3.2
  • 茧1.2.5

文件:

... Models

class Group < ActiveRecord::Base
  has_many :solicitations, :dependent => :destroy
  accepts_nested_attributes_for :solicitations, reject_if: :all_blank

class Solicitation < ActiveRecord::Base
  belongs_to :group

... Controller

class GroupsController < ApplicationController
  before_action :authenticate_user!
  before_action :set_group, only: [:show, :edit, :update, :destroy]
  before_action :set_current_user, only: [:index, :edit, :update, :create]

  def new
    @group = Group.new
    respond_to do |format|
      format.html
      format.json { render json: @group }
    end
  end

  def create
    @group = Group.new(group_params)
    respond_to do |format|
      if @group.save
        format.html { redirect_to action: :index, notice: 'Group was successfully created.' }
        format.json { render json: @group, status: :created, location: @group }
      else
        format.html { render action: "new" }
        format.json { render json: @group.errors, status: :unprocessable_entity }
      end
    end
  end

  private

    def group_params
      params.require(:group).permit( :name, :id,
        solicitations_attributes: [ :id, :email, :name, :role, :_destroy ] )

... Form Partial _solicitation_fields.html.haml

= simple_form_for @group, :html => {:class => 'form-vertical' } do |f|
  = f.error_notification
  .fields
    .row
      .large-12.columns
        = f.input :name, :required => true, placeholder: 'A descriptive group name'
    %hr
      .large-12.columns
      %h4 Group Solicitations
      .large-12.columns
        %table.responsive
          %thead
            %tr
              - headings = ["* Name", "* Email", "* Role", ""]
              - headings.each do |heading|
                %th= heading
          %tbody
            = f.simple_fields_for :solicitations do |solicitation|
              = render 'solicitation_fields', :f => solicitation
            .links
              = link_to_add_association "Add Solicitation?", f, :solicitations, confirm: "Does this work?"
      .large-12.columns
      .row
        .large-12.columns
          = f.error :base
          = f.button :submit, class: "button radius"

... groups.js
$(document).ready(function() {
    $('#solicitations').bind('cocoon:before-insert', function(e,solicitation_to_be_added) {
        solicitation_to_be_added.fadeIn('slow');
    });

    $('#solicitations').bind('cocoon:after-insert', function(e, added_solicitation) {
        //added_solicitation.css("background","red");
    });

    $('#solicitations').bind('cocoon:before-remove', function(e, solicitation) {
        $(this).data('remove-timeout', 1000);
        solicitation.fadeOut('slow');
    })

});...

坦率地说,我在 js 方面很弱。我已经为此工作了几天并且不想退出,所以任何帮助或指导将不胜感激。我已经看到 Bootstrap 需要一些内联包装器才能与 cocoon 和 simple_form 一起使用,但似乎 simple_form 初始化程序与 github 上的 nathanvda 演示示例相比发生了很大变化。

此外,当我明确地将 @group.solicitations.build 放在控制器操作中时,我可以显示部分内容,但我在演示中看不到该过程。

4

1 回答 1

1

我决定用 nested_form gem 代替 cocoon gem,但它也失败了。问题在于主题及其将 gem 的 js 指令放在其自己的特殊清单中的要求。主题的文档没有提到这一点。我没有想到 cocoon.js 没有加载。现在工作正常。

于 2014-02-24T23:59:30.860 回答