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" %><br />
<%= 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?
--
Posted via http://www.ruby-forum.com/.
Aldo Italo 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 marnen-sbuyVjPbboAdnm+yROfE0A@public.gmane.org -- Posted via http://www.ruby-forum.com/.
> > 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 -- Posted via http://www.ruby-forum.com/.
Aldo Italo 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.> > thanksBest, -- Marnen Laibow-Koser http://www.marnen.org marnen-sbuyVjPbboAdnm+yROfE0A@public.gmane.org -- Posted via http://www.ruby-forum.com/.
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 Esco ''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 Italo escribió:> > 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" %><br /> > <%= 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? > -- > Posted via http://www.ruby-forum.com/. > > >
Andrés Cirugeda Esco 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 Esco >i have previous tryed with your solution, but the view page not display the :langs inputs ( display only if i use :lang ). -- Posted via http://www.ruby-forum.com/.
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? -- Posted via http://www.ruby-forum.com/.