I have the following three models created applying the polymorphic concept ========================================================================= class SoftwareCi < ActiveRecord::Base has_one :ci, :as => :content end class HardwareCi < ActiveRecord::Base has_one :ci, :as => :content end class Ci < ActiveRecord::Base belongs_to :content, :polymorphic => true end The table, cis ,contains the following records ============================================ id | ci_number | content_id | content_type ----+----------+-----------+------------+-------------- 1 | CI1 | 1 | SoftwareCi 2 | CI2 | 2 | SoftwareCi 3 | CI3 | 1 | HardwareCi 4 | CI4 | 2 | HardwareCi The table, software_cis ,contains the following records ==================================================== id | asset_tag | status | version ----+-------------------+---------+--------- 1 | AC Logix - AT1 | Status2 | 1.0 2 | RR Logix AT2 | Status3 | 2.3 The table, hardware_cis ,contains the following records ==================================================== id | asset_tag | status | version ----+-------------------+---------+--------- 1 | HCL - AT1 | Status1 | 1.0 2 | IBM - AT2 | Status1 | 2.3 The controller, ci_controller, contains the edit method as follows =============================================================== def edit @ci=Ci.find(1) end My Problem ==========In the edit.rhtml file, I am trying to populate the value of ''version'', an attribute in the software_ci table which is represented by the content_type, SotwareCi. The sample code is given below. <%= text_field ci.content, "version", "size" => 20 %> I am assuming ''ci.content'' in the above code will represent the model and ''version'' will represent the attribute of that model. When executed the above code didn''t work. What is wrong here? How I have to proceed? If we want to simply display the value of ci.content.version, it works but when tried to edit, it doesn''t work Thanks in advance for your help -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Frederick Cheung
2008-Jan-02 14:36 UTC
Re: problem when editing record in polymorphic relation
On 2 Jan 2008, at 14:22, Venu Vallayil wrote:> > My Problem > ==========> In the edit.rhtml file, I am trying to populate the value of > ''version'', > an attribute in the software_ci table which is represented by the > content_type, SotwareCi. The sample code is given below. > > <%= text_field ci.content, "version", "size" => 20 %> >text_field doesn''t work that way - it expects the first parameter to be the name of an instance variable You should look into form_for since it allows you to escape that convention Fred> I am assuming ''ci.content'' in the above code will represent the model > and ''version'' will represent the attribute of that model. > > When executed the above code didn''t work. > What is wrong here? How I have to proceed? > If we want to simply display the value of ci.content.version, it works > but when tried to edit, it doesn''t work > > > Thanks in advance for your help > -- > Posted via http://www.ruby-forum.com/. > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Venu Vallayil
2008-Jan-02 14:57 UTC
Re: problem when editing record in polymorphic relation
Frederick Cheung wrote:> On 2 Jan 2008, at 14:22, Venu Vallayil wrote: >> >> My Problem >> ==========>> In the edit.rhtml file, I am trying to populate the value of >> ''version'', >> an attribute in the software_ci table which is represented by the >> content_type, SotwareCi. The sample code is given below. >> >> <%= text_field ci.content, "version", "size" => 20 %> >> > text_field doesn''t work that way - it expects the first parameter to > be the name of an instance variable > You should look into form_for since it allows you to escape that > convention > > FredI created as follows but didn''t work <% form_for :ci, @ci, :url => { :action => "update" } do |f| %> CI Name: <%= f.content.text_field :name %> <% end %> Thanks Venu -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Frederick Cheung
2008-Jan-02 15:03 UTC
Re: problem when editing record in polymorphic relation
On 2 Jan 2008, at 14:57, Venu Vallayil wrote:> > Frederick Cheung wrote: >> On 2 Jan 2008, at 14:22, Venu Vallayil wrote: >>> >>> My Problem >>> ==========>>> In the edit.rhtml file, I am trying to populate the value of >>> ''version'', >>> an attribute in the software_ci table which is represented by the >>> content_type, SotwareCi. The sample code is given below. >>> >>> <%= text_field ci.content, "version", "size" => 20 %> >>> >> text_field doesn''t work that way - it expects the first parameter to >> be the name of an instance variable >> You should look into form_for since it allows you to escape that >> convention >> >> Fred > > I created as follows but didn''t work > > <% form_for :ci, @ci, :url => { :action => "update" } do |f| %> > CI Name: <%= f.content.text_field :name %> > <% end %>That doesn''t mean anything - you need form_for :co, @ci.content, ... do |f| f.text_field :name end If the form as a whole should apply to ci rather than its content then you can use fields_for to create the fields (without creating the <form> tag) Fred --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Venu Vallayil
2008-Jan-02 15:34 UTC
Re: problem when editing record in polymorphic relation
Frederick Cheung wrote:> On 2 Jan 2008, at 14:57, Venu Vallayil wrote: > >>>> >> >> <% form_for :ci, @ci, :url => { :action => "update" } do |f| %> >> CI Name: <%= f.content.text_field :name %> >> <% end %> > > That doesn''t mean anything - you need > form_for :co, @ci.content, ... do |f| > f.text_field :name > end > > If the form as a whole should apply to ci rather than its content then > you can use fields_for to create the fields (without creating the > <form> tag) > > FredFred......will you be able to show me a sample code that tells how a record is to be edited when there exists a polymorphic relation as shown in the starting thread of this talk Thanks Venu -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Frederick Cheung
2008-Jan-02 15:43 UTC
Re: problem when editing record in polymorphic relation
On 2 Jan 2008, at 15:34, Venu Vallayil wrote:> > Frederick Cheung wrote: >> On 2 Jan 2008, at 14:57, Venu Vallayil wrote: >> >>>>> >>> >>> <% form_for :ci, @ci, :url => { :action => "update" } do |f| %> >>> CI Name: <%= f.content.text_field :name %> >>> <% end %> >> >> That doesn''t mean anything - you need >> form_for :co, @ci.content, ... do |f| >> f.text_field :name >> end >> >> If the form as a whole should apply to ci rather than its content >> then >> you can use fields_for to create the fields (without creating the >> <form> tag) >> >> Fred > > Fred......will you be able to show me a sample code that tells how a > record is to be edited when there exists a polymorphic relation as > shown > in the starting thread of this talk >The polymorphism is (I think) irrelevant, it''s the fact that there is an association. There is a good series on railscasts.com about complex forms. Fred> Thanks > Venu > -- > Posted via http://www.ruby-forum.com/. > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Venu Vallayil
2008-Jan-02 15:52 UTC
Re: problem when editing record in polymorphic relation
Frederick Cheung wrote:> On 2 Jan 2008, at 15:34, Venu Vallayil wrote: > >>> That doesn''t mean anything - you need >> >> Fred......will you be able to show me a sample code that tells how a >> record is to be edited when there exists a polymorphic relation as >> shown >> in the starting thread of this talk >> > The polymorphism is (I think) irrelevant, it''s the fact that there is > an association. There is a good series on railscasts.com about complex > forms. > > FredBut nobody talks/shows the code about editing a record keeping the concept I introduced in my starting thread....seems to be i am lost somewhere....can''t proceed.....thanks for your support. Really appreciate your support. -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---