English 中文(简体)
铁路/水管问题,部分和封套形式
原标题:Ruby on Rails/Haml issues with partials and nested forms

我正在开发一种宽松的形式,并利用Ryan Bates铁路预报。 我正在形成一种使用部分的典型形式。

= form_for(@project, :html => { :class =>  addProjectForm  }) do |f|
  ...
  %p
    = f.fields_for :crew_members do |crew|
      #fields
      = render  crew_member_fields , :m => crew
      = link_to_add_fields "Add Crew Members", f, :crew_members
  %p

然后,我叫一个助手班,能够打上“现场”类,并添加到我的表格中。

module ProjectsHelper
  def link_to_add_fields(name, f, association)
    new_object = f.object.class.reflect_on_association(association).klass.new
    fields = f.fields_for(association, new_object, :child_index => "new_#{association}") do |builder|
      render(association.to_s.singularize + "_fields", :f => builder)
    end
    link_to_function(name, h("add_fields(this, "#{association}", "#{escape_javascript(fields)}")"))
  end
end

然后,助手班就叫作“javascript”处理细节。

function add_fields(link, association, content) {
        var new_id = new Date().getTime();
        var regexp = new RegExp("new_" + association, "g");
        $(link).parent().before(content.replace(regexp, new_id));
}

我要补充的是,我的问题是:

= link_to_add_fields "Add Crew Members", f, :crew_members

我照此错误。

undefined local variable or method `m  for #<#<Class:0xa763964>:0xa761588>

    Extracted source (around line #1):

    1: = m.label "Crew Member Name"
    2: = m.label "Crew Member Role"
    3: %br
    4: = m.text_field :name

因此,这似乎像部分内容没有变本加厉,但如果我没有。

= link_to_add_fields "Add Crew Members", f, :crew_members

因此,部分显示只是罚款。 我对如何下调感到困惑。 担任这一长期职务,但我想得到所有信息。 得到帮助。

最佳回答

I think you have a typo in the helper.

module ProjectsHelper
  def link_to_add_fields(name, f, association)
    new_object = f.object.class.reflect_on_association(association).klass.new
    fields = f.fields_for(association, new_object, :child_index => "new_#{association}") do |builder|
      render(association.to_s.singularize + "_fields", :f => builder)
    end
    link_to_function(name, h("add_fields(this, "#{association}", "#{escape_javascript(fields)}")"))
  end
end

render(association.to_s.singularize + "_fields", :f => builder) should be render(association.to_s.singularize + "_fields", :m => builder)

问题回答

暂无回答




相关问题
rails collection_select vs. select

collection_select and select Rails helpers: Which one should I use? I can t see a difference in both ways. Both helpers take a collection and generates options tags inside a select tag. Is there a ...

SSL slowness in EC2

We ve deployed our rails app to EC2. In our setup, we have two proxies on small instances behind round-robin DNS. These run nginx load balancers for a dynamically growing and shrinking farm of web ...

Auth-code with A-Za-z0-9 to use in an URL parameter

As part of a web application I need an auth-code to pass as a URL parameter. I am currently using (in Rails) : Digest::SHA1.hexdigest((object_id + rand(255)).to_s) Which provides long strings like : ...

RubyCAS-Client question: Rails

I ve installed RubyCAS-Client version 2.1.0 as a plugin within a rails app. It s working, but I d like to remove the ?ticket= in the url. Is this possible?

activerecord has_many :through find with one sql call

I have a these 3 models: class User < ActiveRecord::Base has_many :permissions, :dependent => :destroy has_many :roles, :through => :permissions end class Permission < ActiveRecord::...

Ordering a hash to xml: Rails

I m building an xml document from a hash. The xml attributes need to be in order. How can this be accomplished? hash.to_xml

Text Editor for Ruby-on-Rails

guys which text editor is good for Rubyonrails? i m using Windows and i was using E-Texteditor but its not free n its expired now can anyone plese tell me any free texteditor? n which one is best an ...

How to get SQL queries for each user where env is production

I’m developing an application dedicated to generate statistical reports, I would like that user after saving their stat report they save sql queries too. To do that I wrote the following module: ...

热门标签