0

我有这个 HAML

-content_for :primary_content do
  #available-disclosures-container
    .message-container.information-container
      %h3=(t "headings.influencers.disclosures.new")
      %p=raw((t "influencers.instructions.disclosures.new"))
    =render "sidebar/disclosures/list", :disclosures => Disclosure.basics, :show_link => true, :selectable => true, :usable => false

  #disclosure-form-container{:style => "display:none;"}
    = form_for([:sidebar,@disclosure], :html => {:id => "disclosure-form", :remote => true}) do |f|

我不知道为什么,但最后一行:

= form_for([:sidebar,@disclosure], :html => {:id => "disclosure-form", :remote => true}) do |f|

导致此错误:

undefined method `model_name' for NilClass:Class

6:     =render "sidebar/disclosures/list", :disclosures => Disclosure.basics, :show_link => true, :selectable => true, :usable => false
7: 
8:   #disclosure-form-container{:style => "display:none;"}
9:     = form_for([:sidebar,@disclosure], :html => {:id => "disclosure-form", :remote => true}) do |f|
10:       %p
11:         =f.label :display_as, (t :select_disclosure_type)
12:         =f.select :display_as, options_from_collection_for_select(Disclosure.basics, :display_as, :name, f.object.display_as)

知道是什么元素导致了这个问题吗?

谢谢!

4

1 回答 1

2

这看起来不对:

= form_for([:sidebar, @disclosure]) do |f|

看起来您正在尝试使用侧边栏符号生成路线,该符号需要是公开所属的模型的实例才能工作。

很难确定,但也许这就是你要找的:

= form_for(@disclosure), :url => [:sidebar, @disclosure] do |f|
于 2012-04-20T18:26:20.617 回答