hi, i i have a model (Page) and i want to put their multilanguage text
with a polimorphic association model (Lang), because i want to use in
future this model for containing others modules text (example: Category,
Notice, ecc…).
now i make this code on models:
class Page < ActiveRecord::Base
has_many :langs, :as => :langable
accepts_nested_attributes_for :langs
end
class Lang < ActiveRecord::Base
belongs_to :langable, :polymorphic => true
#other code …
end
i create form Page with the nested lang fields (i create the new page
with one record on the model Lang, for insert others Langs i use
separated forms):
<% form_for([:admin, @page], :html => {:multipart => true}) do |f| %>
<%= error_messages_for :page %>
<%# …others fields … %>
<% f.fields_for :lang do |l| %>
<%= l.hidden_field :langcode, :value => “en” %>
<%= l.label :title, “title” %>
<%= l.text_field :title %>
<%# …others fields … %>
<% end %>
<%# …others fields … %>
<% end %>
the controller is the same than previously i make the nested modify:
#other code …
CREATE PAGE
def create
@page = Page.new(params[:page])
respond_to do |format|
if @page.save
format.html { redirect_to([:admin, @page]) }
else
format.html { render :action => “new” }
end
end
end
#other code …
but on create page i retrieve this error:
unknown attribute: lang
/Users/xxx/.gem/ruby/1.8/gems/activerecord-2.3.2/lib/active_record/base.rb:2745:in
attributes=' /Users/xxx/.gem/ruby/1.8/gems/activerecord-2.3.2/lib/active_record/base.rb:2741:in
each’
/Users/xxx/.gem/ruby/1.8/gems/activerecord-2.3.2/lib/active_record/base.rb:2741:in
attributes=' /Users/xxx/.gem/ruby/1.8/gems/activerecord-2.3.2/lib/active_record/base.rb:2439:in
initialize’
/Users/xxx/Sites/htdocs/rails/my_site/app/controllers/admin/pages_controller.rb:33:in
new' /Users/xxx/Sites/htdocs/rails/my_site/app/controllers/admin/pages_controller.rb:33:in
create’
i have verified the code but all seem ok.
any idea?