1

我有一个名为local的模型,这个模型有很多这样的门户

class Portal < ActiveRecord::Base
    belongs_to :local, :class_name => "Local"   
end

class Local < ActiveRecord::Base
    has_many :portales, :class_name => "Portal", :dependent => :destroy
    accepts_nested_attributes_for :portales, :allow_destroy => true
end

问题是当我将参数分配给本地时,控制台显示:

NoMethodError Exception: undefined method `portal' for #<Local:0x007f9cd50a7f20>

这是我的控制器和表单:

控制器:

def new_portal
    @local = Local.new
    if request.post?
        @local.update_attributes params[:local]
    end
end

形式:

<%= form_for @local, :url => {:action => 'new_portal'}, :html => {:id => 'formulario_local', :multipart => true, :method => 'post'} do |f| %>
    <%= f.fields_for :portal do |portal_form| -%>
      <div id="porcentaje_barra">
        <%= portal_form.select 'opacidad_barra', generate_options_from_hash(@porcentaje_opacidad) %>
      </div>
      <div id="texto_barra">
        <%= image_tag 'editor/texto.png', :size => '30x30'%>
        <h5>Texto</h5>
      </div>
      <div id="tipo_de_letra_barra">
        <%= portal_form.select 'tipo_letra_barra', generate_options_from_hash(@tipos_de_letra),:prompt => 'Selecciona' %>
      </div>
      <div id="estilo_fuente_barra">
        <%= portal_form.select 'estilo_letra_barra', generate_options_from_hash(@estilo_de_letra), style: 'width:70px'%>
      </div>
      <div id="tam_fuente_barra">
        <%= portal_form.select 'tamano_letra_barra', generate_options_from_hash(@tamano_de_letra), style: 'width:50px'%>
      </div>
    <% end %>
<% end %>

而且,这是我的变化:

ActiveSupport::Inflector.inflections do |inflect|
inflect.irregular 'usuario', 'usuarios'
inflect.irregular 'producto', 'productos'
inflect.irregular 'portal', 'portales'
inflect.irregular 'local', 'locales'
end

我不知道是什么问题,视图显示了所有表单。

感谢您的帮助(对不起我的英语),

乔治 -

4

1 回答 1

1

第一的,

<%= f.fields_for :portal do |portal_form| -%>

<%= f.fields_for :portales do |portal_form| -%>
于 2012-08-20T20:50:31.573 回答