Problem with polymorphic nested attributes

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:ineach’
/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:ininitialize’
/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:increate’

i have verified the code but all seem ok.
any idea?

Aldo I. wrote:

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…).

Um, why bother to do this? Rails has its own i18n infrastructure –
just use that.

Best,

Marnen Laibow-Koser
http://www.marnen.org
[email protected]

Um, why bother to do this? Rails has its own i18n infrastructure –
just use that.

i use i18n for static texts in /locales, how can use i18n infrastructure
for DB contents?

thanks

Aldo I. wrote:
[…]

i use i18n for static texts in /locales, how can use i18n infrastructure
for DB contents?

OK, now I see what you’re trying for. I’ll give that some more thought;
in the meantime, it may be worth asking that question on the Rails I18n
list.

thanks

Best,

Marnen Laibow-Koser
http://www.marnen.org
[email protected]

I think your fields_for line is wrong. It should match the association
name ‘langs’:

<% f.fields_for :langs do |l| %>

Regards

Andrés Cirugeda E.

‘All we have to decide is what to do with the time that is given to us’.

El 28/07/2009, a las 20:22, Aldo I.
escribió:

Andrés Cirugeda E. wrote:

I think your fields_for line is wrong. It should match the association
name ‘langs’:

<% f.fields_for :langs do |l| %>

Regards

Andr�s Cirugeda E.

i have previous tryed with your solution, but the view page not display
the :langs inputs ( display only if i use :lang ).

i have tried globalize2: i don’t find the solutions for my problems.

because i have my pages with associated images, attachemnts and other,
in practice, in administration, when i create a Page, successively i
populated him with photos ,attachments and other.
The broblem of globalize2 is wich it create redundant pages for ever
language… i don’t need this solution, but i want created translated
text inner the mother page (similar to create the other childs, eg:
photos, attachments, ecc…)

Others have a solution?

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs