With this ER diagram. should the suggestions table be polymorphic? Or OPTION 2: should i just have two separate tables called business_suggestion and city_suggestion? I was thinking polymorphic since the columns first_name, last_name and email will be used in the business_suggestion and city_suggestion tables. If I go with OPTION 2, then the business_suggestion and city_suggestion tables will have first_name, last_name and email columns. Which is a bit redundant... Here is the ER diagram: http://imagebin.org/113043 What are your thoughts? -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
I''d be less worried about the columns, but more focused on the entities involved... Your ''suggestion'' seems to be analogous to a ''contact'', and a contact may well be tied to a business and/or a city (business leaders often sit on local/city councils/chambers/whatever they are called - sometimes with separate phone/address/email, sometimes not). So I could perhaps see: Business has_many :suggestionlinks, :as => :sugglinkable has_many :suggestions, :through => :suggestionlinks City has_many :suggestionlinks, :as => :sugglinkable has_many :suggestions, :through => :suggestionlinks Suggestion has_many :suggestionlinks has_many :businesses, :through => :suggestionlinks, :source => :business, :conditions => "suggestionlink.sugglinkable_type = ''Business''" has_many :cities, :through => :suggestionlinks, :source => :city, :conditions => "suggestionlink.sugglinkable_type = ''City''" Suggestionlink # id INT # suggestion_id INT # sugglinkable_type VARCHAR() # sugglinkable_id INT belongs_to :suggestion belongs_to :sugglinkable, :polymorphic => true belongs_to :business, :class_name => ''Business'', :foreign_key => ''sugglinkable_id'' belongs_to :city, :class_name => ''City'', :foreign_key => ''sugglinkable_id'' Or something like that -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Ar, what I am trying to do is allow users to suggest a business and or city. I want to have a database record for this. Why do I need a Suggestionlink model? On Sep 7, 9:42 pm, Ar Chron <li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> I''d be less worried about the columns, but more focused on the entities > involved... > > Your ''suggestion'' seems to be analogous to a ''contact'', and a contact > may well be tied to a business and/or a city (business leaders often sit > on local/city councils/chambers/whatever they are called - sometimes > with separate phone/address/email, sometimes not). > > So I could perhaps see: > > Business > has_many :suggestionlinks, :as => :sugglinkable > has_many :suggestions, :through => :suggestionlinks > > City > has_many :suggestionlinks, :as => :sugglinkable > has_many :suggestions, :through => :suggestionlinks > > Suggestion > has_many :suggestionlinks > has_many :businesses, :through => :suggestionlinks, :source => > :business, :conditions => "suggestionlink.sugglinkable_type > ''Business''" > has_many :cities, :through => :suggestionlinks, :source => :city, > :conditions => "suggestionlink.sugglinkable_type = ''City''" > > Suggestionlink > # id INT > # suggestion_id INT > # sugglinkable_type VARCHAR() > # sugglinkable_id INT > belongs_to :suggestion > belongs_to :sugglinkable, :polymorphic => true > belongs_to :business, :class_name => ''Business'', :foreign_key => > ''sugglinkable_id'' > belongs_to :city, :class_name => ''City'', :foreign_key => > ''sugglinkable_id'' > > Or something like that > -- > Posted viahttp://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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Also note, a user does not need to be registered or signed in to suggest. Hence, why they should provide their first_name, last_name and email On Sep 7, 10:08 pm, Christian Fazzini <christian.fazz...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Ar, what I am trying to do is allow users to suggest a business and or > city. I want to have a database record for this. > > Why do I need a Suggestionlink model? > > On Sep 7, 9:42 pm, Ar Chron <li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote: > > > I''d be less worried about the columns, but more focused on the entities > > involved... > > > Your ''suggestion'' seems to be analogous to a ''contact'', and a contact > > may well be tied to a business and/or a city (business leaders often sit > > on local/city councils/chambers/whatever they are called - sometimes > > with separate phone/address/email, sometimes not). > > > So I could perhaps see: > > > Business > > has_many :suggestionlinks, :as => :sugglinkable > > has_many :suggestions, :through => :suggestionlinks > > > City > > has_many :suggestionlinks, :as => :sugglinkable > > has_many :suggestions, :through => :suggestionlinks > > > Suggestion > > has_many :suggestionlinks > > has_many :businesses, :through => :suggestionlinks, :source => > > :business, :conditions => "suggestionlink.sugglinkable_type > > ''Business''" > > has_many :cities, :through => :suggestionlinks, :source => :city, > > :conditions => "suggestionlink.sugglinkable_type = ''City''" > > > Suggestionlink > > # id INT > > # suggestion_id INT > > # sugglinkable_type VARCHAR() > > # sugglinkable_id INT > > belongs_to :suggestion > > belongs_to :sugglinkable, :polymorphic => true > > belongs_to :business, :class_name => ''Business'', :foreign_key => > > ''sugglinkable_id'' > > belongs_to :city, :class_name => ''City'', :foreign_key => > > ''sugglinkable_id'' > > > Or something like that > > -- > > Posted viahttp://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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Ar, your solution is not very clear. Can you also indicate columns and migration file On Sep 7, 9:42 pm, Ar Chron <li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> I''d be less worried about the columns, but more focused on the entities > involved... > > Your ''suggestion'' seems to be analogous to a ''contact'', and a contact > may well be tied to a business and/or a city (business leaders often sit > on local/city councils/chambers/whatever they are called - sometimes > with separate phone/address/email, sometimes not). > > So I could perhaps see: > > Business > has_many :suggestionlinks, :as => :sugglinkable > has_many :suggestions, :through => :suggestionlinks > > City > has_many :suggestionlinks, :as => :sugglinkable > has_many :suggestions, :through => :suggestionlinks > > Suggestion > has_many :suggestionlinks > has_many :businesses, :through => :suggestionlinks, :source => > :business, :conditions => "suggestionlink.sugglinkable_type > ''Business''" > has_many :cities, :through => :suggestionlinks, :source => :city, > :conditions => "suggestionlink.sugglinkable_type = ''City''" > > Suggestionlink > # id INT > # suggestion_id INT > # sugglinkable_type VARCHAR() > # sugglinkable_id INT > belongs_to :suggestion > belongs_to :sugglinkable, :polymorphic => true > belongs_to :business, :class_name => ''Business'', :foreign_key => > ''sugglinkable_id'' > belongs_to :city, :class_name => ''City'', :foreign_key => > ''sugglinkable_id'' > > Or something like that > -- > Posted viahttp://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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Hmm... seems my interpretation of what you are attempting to do doesn''t match very well with your unstated goals... You were asking whether the suggestion model should be polymorphic... Sooo, what exactly is a suggestion in the context of your application (what are your users doing)? -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Hi Ar, End-users can either be registered or non-registered users. Any type of user can suggest a business and a city. When they suggest a city, they have to put in their first_name, last_name, email and city name. When they suggest a business. They have to put in their first_name, last_name, email, business name and business address. Initially, I had it working with two separate models: city_suggestion and business_suggestion. However, since both tables have fields that can be reused (i.e. first_name, last_name, email), I was thinking of using a polymorphic association. I am not sure if this is the right approach or whether I should have just stuck with my original solution (i.e. two separate tables: city_suggestion and business_suggestion) On Sep 7, 11:02 pm, Ar Chron <li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> Hmm... seems my interpretation of what you are attempting to do doesn''t > match very well with your unstated goals... You were asking whether the > suggestion model should be polymorphic... > > Sooo, what exactly is a suggestion in the context of your application > (what are your users doing)? > -- > Posted viahttp://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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
no you need single table inheritance is way better in your case , read a bit about STI, it lets you create one table and one model and then inherit from that model list this class BaseSugesstions < ActiveRecord :: base attr_accessible first_name, last_name, email, city_name, business_name end then class citySugesstions < BaseSugesstions attr_accessible first_name, last_name, email, city_name end class BaseSugesstions < BaseSugesstions attr_accessible first_name, last_name, email, business_name end one table should on the database should have all the field defined in BaseSugesstions On Tue, Sep 7, 2010 at 11:25 AM, Christian Fazzini < christian.fazzini-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Hi Ar, > > End-users can either be registered or non-registered users. Any type > of user can suggest a business and a city. > > When they suggest a city, they have to put in their first_name, > last_name, email and city name. > > When they suggest a business. They have to put in their first_name, > last_name, email, business name and business address. > > Initially, I had it working with two separate models: city_suggestion > and business_suggestion. However, since both tables have fields that > can be reused (i.e. first_name, last_name, email), I was thinking of > using a polymorphic association. > > I am not sure if this is the right approach or whether I should have > just stuck with my original solution (i.e. two separate tables: > city_suggestion and business_suggestion) > > > On Sep 7, 11:02 pm, Ar Chron <li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote: > > Hmm... seems my interpretation of what you are attempting to do doesn''t > > match very well with your unstated goals... You were asking whether the > > suggestion model should be polymorphic... > > > > Sooo, what exactly is a suggestion in the context of your application > > (what are your users doing)? > > -- > > Posted viahttp://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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org<rubyonrails-talk%2Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> > . > For more options, visit this group at > http://groups.google.com/group/rubyonrails-talk?hl=en. > >-- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Thanks redhames. Will look into this On Sep 8, 12:02 am, radhames brito <rbri...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> no you need single table inheritance > > is way better in your case , read a bit about STI, it lets you create one > table and one model and then inherit from that model > > list this > > class BaseSugesstions < ActiveRecord :: base > > attr_accessible first_name, last_name, email, city_name, business_name > > end > > then > > class citySugesstions < BaseSugesstions > > attr_accessible first_name, last_name, email, city_name > > end > > class BaseSugesstions < BaseSugesstions > > attr_accessible first_name, last_name, email, business_name > > end > > one table should on the database should have all the field defined in > BaseSugesstions > > On Tue, Sep 7, 2010 at 11:25 AM, Christian Fazzini < > > christian.fazz...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > Hi Ar, > > > End-users can either be registered or non-registered users. Any type > > of user can suggest a business and a city. > > > When they suggest a city, they have to put in their first_name, > > last_name, email and city name. > > > When they suggest a business. They have to put in their first_name, > > last_name, email, business name and business address. > > > Initially, I had it working with two separate models: city_suggestion > > and business_suggestion. However, since both tables have fields that > > can be reused (i.e. first_name, last_name, email), I was thinking of > > using a polymorphic association. > > > I am not sure if this is the right approach or whether I should have > > just stuck with my original solution (i.e. two separate tables: > > city_suggestion and business_suggestion) > > > On Sep 7, 11:02 pm, Ar Chron <li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote: > > > Hmm... seems my interpretation of what you are attempting to do doesn''t > > > match very well with your unstated goals... You were asking whether the > > > suggestion model should be polymorphic... > > > > Sooo, what exactly is a suggestion in the context of your application > > > (what are your users doing)? > > > -- > > > Posted viahttp://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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > > To unsubscribe from this group, send email to > > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org<rubyonrails-talk%2Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> > > . > > For more options, visit this group at > >http://groups.google.com/group/rubyonrails-talk?hl=en.-- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Radhames, how do I go about creating the controllers for CitySuggestion and BusinessSuggestion? Can I use the scaffold generator for these two? Or should I use the Suggestions controller to handle both? For example, where is the view/form to add new CitySuggestion? Should this be in the Suggestions controller? I''m a bit confused here... On Sep 8, 12:02 am, radhames brito <rbri...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> no you need single table inheritance > > is way better in your case , read a bit about STI, it lets you create one > table and one model and then inherit from that model > > list this > > class BaseSugesstions < ActiveRecord :: base > > attr_accessible first_name, last_name, email, city_name, business_name > > end > > then > > class citySugesstions < BaseSugesstions > > attr_accessible first_name, last_name, email, city_name > > end > > class BaseSugesstions < BaseSugesstions > > attr_accessible first_name, last_name, email, business_name > > end > > one table should on the database should have all the field defined in > BaseSugesstions > > On Tue, Sep 7, 2010 at 11:25 AM, Christian Fazzini < > > christian.fazz...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > Hi Ar, > > > End-users can either be registered or non-registered users. Any type > > of user can suggest a business and a city. > > > When they suggest a city, they have to put in their first_name, > > last_name, email and city name. > > > When they suggest a business. They have to put in their first_name, > > last_name, email, business name and business address. > > > Initially, I had it working with two separate models: city_suggestion > > and business_suggestion. However, since both tables have fields that > > can be reused (i.e. first_name, last_name, email), I was thinking of > > using a polymorphic association. > > > I am not sure if this is the right approach or whether I should have > > just stuck with my original solution (i.e. two separate tables: > > city_suggestion and business_suggestion) > > > On Sep 7, 11:02 pm, Ar Chron <li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote: > > > Hmm... seems my interpretation of what you are attempting to do doesn''t > > > match very well with your unstated goals... You were asking whether the > > > suggestion model should be polymorphic... > > > > Sooo, what exactly is a suggestion in the context of your application > > > (what are your users doing)? > > > -- > > > Posted viahttp://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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > > To unsubscribe from this group, send email to > > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org<rubyonrails-talk%2Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> > > . > > For more options, visit this group at > >http://groups.google.com/group/rubyonrails-talk?hl=en.-- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
well, from now on you can forget about the base model if you want to and use everything as if they are 3 table and 3 models, do as you would normally would with a simple model just dont use the base BaseSugesstions unless is an admin and want to do something special. create scaffolds for citySugesstions and BussinesSuggestion (by the way there is a typo en my example the second class is supposed to be BussinesSuggestion not BaseSuggestion) with free access to create and their own views and forms. For adminsitration purposes and for your benefit create a basesugetion controller for staticstics, un the base model you can use all kinds of scopes to check and compare. On Tue, Sep 7, 2010 at 3:30 PM, Christian Fazzini < christian.fazzini-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Radhames, how do I go about creating the controllers for > CitySuggestion and BusinessSuggestion? Can I use the scaffold > generator for these two? > > Or should I use the Suggestions controller to handle both? For > example, where is the view/form to add new CitySuggestion? Should this > be in the Suggestions controller? > > I''m a bit confused here... > > On Sep 8, 12:02 am, radhames brito <rbri...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > no you need single table inheritance > > > > is way better in your case , read a bit about STI, it lets you create one > > table and one model and then inherit from that model > > > > list this > > > > class BaseSugesstions < ActiveRecord :: base > > > > attr_accessible first_name, last_name, email, city_name, business_name > > > > end > > > > then > > > > class citySugesstions < BaseSugesstions > > > > attr_accessible first_name, last_name, email, city_name > > > > end > > > > class BaseSugesstions < BaseSugesstions > > > > attr_accessible first_name, last_name, email, business_name > > > > end > > > > one table should on the database should have all the field defined in > > BaseSugesstions > > > > On Tue, Sep 7, 2010 at 11:25 AM, Christian Fazzini < > > > > christian.fazz...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > Hi Ar, > > > > > End-users can either be registered or non-registered users. Any type > > > of user can suggest a business and a city. > > > > > When they suggest a city, they have to put in their first_name, > > > last_name, email and city name. > > > > > When they suggest a business. They have to put in their first_name, > > > last_name, email, business name and business address. > > > > > Initially, I had it working with two separate models: city_suggestion > > > and business_suggestion. However, since both tables have fields that > > > can be reused (i.e. first_name, last_name, email), I was thinking of > > > using a polymorphic association. > > > > > I am not sure if this is the right approach or whether I should have > > > just stuck with my original solution (i.e. two separate tables: > > > city_suggestion and business_suggestion) > > > > > On Sep 7, 11:02 pm, Ar Chron <li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote: > > > > Hmm... seems my interpretation of what you are attempting to do > doesn''t > > > > match very well with your unstated goals... You were asking whether > the > > > > suggestion model should be polymorphic... > > > > > > Sooo, what exactly is a suggestion in the context of your application > > > > (what are your users doing)? > > > > -- > > > > Posted viahttp://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<rubyonrails-talk%2Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> > <rubyonrails-talk%2Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org<rubyonrails-talk%252Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> > > > > > . > > > For more options, visit this group at > > >http://groups.google.com/group/rubyonrails-talk?hl=en. > > -- > 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org<rubyonrails-talk%2Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> > . > For more options, visit this group at > http://groups.google.com/group/rubyonrails-talk?hl=en. > >-- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Hi Redhames, Ok my form for city_suggestions looks like: <% form_for @city_suggestion do |f| %> <%= f.error_messages %> <p> <%= f.label :first_name %><br /> <%= f.text_field :first_name %> </p> <p> <%= f.label :last_name %><br /> <%= f.text_area :last_name %> </p> <p> <%= f.label :email %><br /> <%= f.text_field :email %> </p> <p> <%= f.label :city_name %><br /> <%= f.text_field :city_name %> </p> <p> <%= f.submit ''Save'' %> </p> <% end %> When I submit this, it saves this into the Suggestions table. However, the entry is not saved in the CitySuggestions table. Should I have a line in my CitySuggestions that explicitly saves the entry to this table as well? Or is RoR supposed to do this automatically? On Sep 8, 5:46 am, radhames brito <rbri...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> well, from now on you can forget about the base model if you want to and use > everything as if they are 3 table and 3 models, do as you would normally > would with a simple model just dont use the base BaseSugesstions unless is > an admin and want to do something special. create scaffolds for > citySugesstions and BussinesSuggestion (by the way there is a typo en my > example the second class is supposed to be BussinesSuggestion not > BaseSuggestion) with free access to create and their own views and forms. > For adminsitration purposes and for your benefit create a basesugetion > controller for staticstics, un the base model you can use all kinds of > scopes to check and compare. > > On Tue, Sep 7, 2010 at 3:30 PM, Christian Fazzini < > > christian.fazz...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > Radhames, how do I go about creating the controllers for > > CitySuggestion and BusinessSuggestion? Can I use the scaffold > > generator for these two? > > > Or should I use the Suggestions controller to handle both? For > > example, where is the view/form to add new CitySuggestion? Should this > > be in the Suggestions controller? > > > I''m a bit confused here... > > > On Sep 8, 12:02 am, radhames brito <rbri...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > no you need single table inheritance > > > > is way better in your case , read a bit about STI, it lets you create one > > > table and one model and then inherit from that model > > > > list this > > > > class BaseSugesstions < ActiveRecord :: base > > > > attr_accessible first_name, last_name, email, city_name, business_name > > > > end > > > > then > > > > class citySugesstions < BaseSugesstions > > > > attr_accessible first_name, last_name, email, city_name > > > > end > > > > class BaseSugesstions < BaseSugesstions > > > > attr_accessible first_name, last_name, email, business_name > > > > end > > > > one table should on the database should have all the field defined in > > > BaseSugesstions > > > > On Tue, Sep 7, 2010 at 11:25 AM, Christian Fazzini < > > > > christian.fazz...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > Hi Ar, > > > > > End-users can either be registered or non-registered users. Any type > > > > of user can suggest a business and a city. > > > > > When they suggest a city, they have to put in their first_name, > > > > last_name, email and city name. > > > > > When they suggest a business. They have to put in their first_name, > > > > last_name, email, business name and business address. > > > > > Initially, I had it working with two separate models: city_suggestion > > > > and business_suggestion. However, since both tables have fields that > > > > can be reused (i.e. first_name, last_name, email), I was thinking of > > > > using a polymorphic association. > > > > > I am not sure if this is the right approach or whether I should have > > > > just stuck with my original solution (i.e. two separate tables: > > > > city_suggestion and business_suggestion) > > > > > On Sep 7, 11:02 pm, Ar Chron <li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote: > > > > > Hmm... seems my interpretation of what you are attempting to do > > doesn''t > > > > > match very well with your unstated goals... You were asking whether > > the > > > > > suggestion model should be polymorphic... > > > > > > Sooo, what exactly is a suggestion in the context of your application > > > > > (what are your users doing)? > > > > > -- > > > > > Posted viahttp://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@googlegroups.com > > . > > > > To unsubscribe from this group, send email to > > > > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org<rubyonrails-talk%2Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> > > <rubyonrails-talk%2Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org<rubyonrails-talk%252Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> > > > > > . > > > > For more options, visit this group at > > > >http://groups.google.com/group/rubyonrails-talk?hl=en. > > > -- > > 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > > To unsubscribe from this group, send email to > > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org<rubyonrails-talk%2Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> > > . > > For more options, visit this group at > >http://groups.google.com/group/rubyonrails-talk?hl=en.-- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
errr, there was suppose to be only on table, and 3 model, one that really is the table and the other that inherit from the base one, thats why it does not save to the citysuggestions table, its not suppose to exist, you are user the same table for both models because their only difference are 2 fields. Treat city_sugestions as if it has its own table , but dont create a table for it. I forgot to maention that the table should have a field called type so that when active record saves , it will save what type of sugestions you are saving to read a sugestion user sugestion[:type]= city_sugestion or just do City_sugestion.find(:all) i have to go to work no ill be available in 40 mintutes if you need more details On Thu, Sep 9, 2010 at 8:57 AM, Christian Fazzini < christian.fazzini-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Hi Redhames, > > Ok my form for city_suggestions looks like: > > <% form_for @city_suggestion do |f| %> > <%= f.error_messages %> > > <p> > <%= f.label :first_name %><br /> > <%= f.text_field :first_name %> > </p> > <p> > <%= f.label :last_name %><br /> > <%= f.text_area :last_name %> > </p> > <p> > <%= f.label :email %><br /> > <%= f.text_field :email %> > </p> > <p> > <%= f.label :city_name %><br /> > <%= f.text_field :city_name %> > </p> > > <p> > <%= f.submit ''Save'' %> > </p> > <% end %> > > When I submit this, it saves this into the Suggestions table. However, > the entry is not saved in the CitySuggestions table. Should I have a > line in my CitySuggestions that explicitly saves the entry to this > table as well? Or is RoR supposed to do this automatically? > > On Sep 8, 5:46 am, radhames brito <rbri...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > well, from now on you can forget about the base model if you want to and > use > > everything as if they are 3 table and 3 models, do as you would normally > > would with a simple model just dont use the base BaseSugesstions unless > is > > an admin and want to do something special. create scaffolds for > > citySugesstions and BussinesSuggestion (by the way there is a typo en my > > example the second class is supposed to be BussinesSuggestion not > > BaseSuggestion) with free access to create and their own views and forms. > > For adminsitration purposes and for your benefit create a basesugetion > > controller for staticstics, un the base model you can use all kinds of > > scopes to check and compare. > > > > On Tue, Sep 7, 2010 at 3:30 PM, Christian Fazzini < > > > > christian.fazz...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > Radhames, how do I go about creating the controllers for > > > CitySuggestion and BusinessSuggestion? Can I use the scaffold > > > generator for these two? > > > > > Or should I use the Suggestions controller to handle both? For > > > example, where is the view/form to add new CitySuggestion? Should this > > > be in the Suggestions controller? > > > > > I''m a bit confused here... > > > > > On Sep 8, 12:02 am, radhames brito <rbri...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > no you need single table inheritance > > > > > > is way better in your case , read a bit about STI, it lets you create > one > > > > table and one model and then inherit from that model > > > > > > list this > > > > > > class BaseSugesstions < ActiveRecord :: base > > > > > > attr_accessible first_name, last_name, email, city_name, > business_name > > > > > > end > > > > > > then > > > > > > class citySugesstions < BaseSugesstions > > > > > > attr_accessible first_name, last_name, email, city_name > > > > > > end > > > > > > class BaseSugesstions < BaseSugesstions > > > > > > attr_accessible first_name, last_name, email, business_name > > > > > > end > > > > > > one table should on the database should have all the field defined in > > > > BaseSugesstions > > > > > > On Tue, Sep 7, 2010 at 11:25 AM, Christian Fazzini < > > > > > > christian.fazz...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > Hi Ar, > > > > > > > End-users can either be registered or non-registered users. Any > type > > > > > of user can suggest a business and a city. > > > > > > > When they suggest a city, they have to put in their first_name, > > > > > last_name, email and city name. > > > > > > > When they suggest a business. They have to put in their first_name, > > > > > last_name, email, business name and business address. > > > > > > > Initially, I had it working with two separate models: > city_suggestion > > > > > and business_suggestion. However, since both tables have fields > that > > > > > can be reused (i.e. first_name, last_name, email), I was thinking > of > > > > > using a polymorphic association. > > > > > > > I am not sure if this is the right approach or whether I should > have > > > > > just stuck with my original solution (i.e. two separate tables: > > > > > city_suggestion and business_suggestion) > > > > > > > On Sep 7, 11:02 pm, Ar Chron <li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote: > > > > > > Hmm... seems my interpretation of what you are attempting to do > > > doesn''t > > > > > > match very well with your unstated goals... You were asking > whether > > > the > > > > > > suggestion model should be polymorphic... > > > > > > > > Sooo, what exactly is a suggestion in the context of your > application > > > > > > (what are your users doing)? > > > > > > -- > > > > > > Posted viahttp://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<rubyonrails-talk%2Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> > <rubyonrails-talk%2Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org<rubyonrails-talk%252Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> > > > > > <rubyonrails-talk%2Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org<rubyonrails-talk%252Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> > <rubyonrails-talk%252Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org<rubyonrails-talk%25252Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> > > > > > > > > > . > > > > > For more options, visit this group at > > > > >http://groups.google.com/group/rubyonrails-talk?hl=en. > > > > > -- > > > 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<rubyonrails-talk%2Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> > <rubyonrails-talk%2Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org<rubyonrails-talk%252Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> > > > > > . > > > For more options, visit this group at > > >http://groups.google.com/group/rubyonrails-talk?hl=en. > > -- > 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org<rubyonrails-talk%2Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> > . > For more options, visit this group at > http://groups.google.com/group/rubyonrails-talk?hl=en. > >-- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
I thought you said I needed to scaffold the citysuggestion and businesssuggestion? Scaffold generates controllers, views, and models (if they already dont exist)? On Sep 9, 9:20 pm, radhames brito <rbri...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> errr, there was suppose to be only on table, and 3 model, one that really is > the table and the other that inherit from the base one, thats why it does > not save to the citysuggestions table, its not suppose to exist, you are > user the same table for both models because their only difference are 2 > fields. Treat city_sugestions as if it has its own table , but dont create a > table for it. > > I forgot to maention that the table should have a field called type so that > when active record saves , it will save what type of sugestions you are > saving to read a sugestion user sugestion[:type]= city_sugestion or just do > City_sugestion.find(:all) > > i have to go to work no ill be available in 40 mintutes if you need more > details > > On Thu, Sep 9, 2010 at 8:57 AM, Christian Fazzini < > > christian.fazz...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > Hi Redhames, > > > Ok my form for city_suggestions looks like: > > > <% form_for @city_suggestion do |f| %> > > <%= f.error_messages %> > > > <p> > > <%= f.label :first_name %><br /> > > <%= f.text_field :first_name %> > > </p> > > <p> > > <%= f.label :last_name %><br /> > > <%= f.text_area :last_name %> > > </p> > > <p> > > <%= f.label :email %><br /> > > <%= f.text_field :email %> > > </p> > > <p> > > <%= f.label :city_name %><br /> > > <%= f.text_field :city_name %> > > </p> > > > <p> > > <%= f.submit ''Save'' %> > > </p> > > <% end %> > > > When I submit this, it saves this into the Suggestions table. However, > > the entry is not saved in the CitySuggestions table. Should I have a > > line in my CitySuggestions that explicitly saves the entry to this > > table as well? Or is RoR supposed to do this automatically? > > > On Sep 8, 5:46 am, radhames brito <rbri...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > well, from now on you can forget about the base model if you want to and > > use > > > everything as if they are 3 table and 3 models, do as you would normally > > > would with a simple model just dont use the base BaseSugesstions unless > > is > > > an admin and want to do something special. create scaffolds for > > > citySugesstions and BussinesSuggestion (by the way there is a typo en my > > > example the second class is supposed to be BussinesSuggestion not > > > BaseSuggestion) with free access to create and their own views and forms. > > > For adminsitration purposes and for your benefit create a basesugetion > > > controller for staticstics, un the base model you can use all kinds of > > > scopes to check and compare. > > > > On Tue, Sep 7, 2010 at 3:30 PM, Christian Fazzini < > > > > christian.fazz...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > Radhames, how do I go about creating the controllers for > > > > CitySuggestion and BusinessSuggestion? Can I use the scaffold > > > > generator for these two? > > > > > Or should I use the Suggestions controller to handle both? For > > > > example, where is the view/form to add new CitySuggestion? Should this > > > > be in the Suggestions controller? > > > > > I''m a bit confused here... > > > > > On Sep 8, 12:02 am, radhames brito <rbri...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > no you need single table inheritance > > > > > > is way better in your case , read a bit about STI, it lets you create > > one > > > > > table and one model and then inherit from that model > > > > > > list this > > > > > > class BaseSugesstions < ActiveRecord :: base > > > > > > attr_accessible first_name, last_name, email, city_name, > > business_name > > > > > > end > > > > > > then > > > > > > class citySugesstions < BaseSugesstions > > > > > > attr_accessible first_name, last_name, email, city_name > > > > > > end > > > > > > class BaseSugesstions < BaseSugesstions > > > > > > attr_accessible first_name, last_name, email, business_name > > > > > > end > > > > > > one table should on the database should have all the field defined in > > > > > BaseSugesstions > > > > > > On Tue, Sep 7, 2010 at 11:25 AM, Christian Fazzini < > > > > > > christian.fazz...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > > Hi Ar, > > > > > > > End-users can either be registered or non-registered users. Any > > type > > > > > > of user can suggest a business and a city. > > > > > > > When they suggest a city, they have to put in their first_name, > > > > > > last_name, email and city name. > > > > > > > When they suggest a business. They have to put in their first_name, > > > > > > last_name, email, business name and business address. > > > > > > > Initially, I had it working with two separate models: > > city_suggestion > > > > > > and business_suggestion. However, since both tables have fields > > that > > > > > > can be reused (i.e. first_name, last_name, email), I was thinking > > of > > > > > > using a polymorphic association. > > > > > > > I am not sure if this is the right approach or whether I should > > have > > > > > > just stuck with my original solution (i.e. two separate tables: > > > > > > city_suggestion and business_suggestion) > > > > > > > On Sep 7, 11:02 pm, Ar Chron <li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote: > > > > > > > Hmm... seems my interpretation of what you are attempting to do > > > > doesn''t > > > > > > > match very well with your unstated goals... You were asking > > whether > > > > the > > > > > > > suggestion model should be polymorphic... > > > > > > > > Sooo, what exactly is a suggestion in the context of your > > application > > > > > > > (what are your users doing)? > > > > > > > -- > > > > > > > Posted viahttp://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<rubyonrails-talk%2Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> > > <rubyonrails-talk%2Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org<rubyonrails-talk%252Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> > > > > > <rubyonrails-talk%2Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org<rubyonrails-talk%252Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> > > <rubyonrails-talk%252Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org<rubyonrails-talk%25252Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> > > > > > > > . > > > > > > For more options, visit this group at > > > > > >http://groups.google.com/group/rubyonrails-talk?hl=en. > > > > > -- > > > > 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@googlegroups.com > > . > > > > To unsubscribe from this group, send email to > > > > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org<rubyonrails-talk%2Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> > > <rubyonrails-talk%2Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org<rubyonrails-talk%252Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> > > > > > . > > > > For more options, visit this group at > > > >http://groups.google.com/group/rubyonrails-talk?hl=en. > > > -- > > 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > > To unsubscribe from this group, send email to > > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org<rubyonrails-talk%2Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> > > . > > For more options, visit this group at > >http://groups.google.com/group/rubyonrails-talk?hl=en.-- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
I thought you said I needed to scaffold the citysuggestion and businesssuggestion? Scaffold generates controllers, views, and models (if they already dont exist)? If I do rake db:migrate, it generates the tables in the db. Should I remove the migration files that the scaffold generator generates before doing rake db:migrate? On Sep 9, 9:20 pm, radhames brito <rbri...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> errr, there was suppose to be only on table, and 3 model, one that really is > the table and the other that inherit from the base one, thats why it does > not save to the citysuggestions table, its not suppose to exist, you are > user the same table for both models because their only difference are 2 > fields. Treat city_sugestions as if it has its own table , but dont create a > table for it. > > I forgot to maention that the table should have a field called type so that > when active record saves , it will save what type of sugestions you are > saving to read a sugestion user sugestion[:type]= city_sugestion or just do > City_sugestion.find(:all) > > i have to go to work no ill be available in 40 mintutes if you need more > details > > On Thu, Sep 9, 2010 at 8:57 AM, Christian Fazzini < > > christian.fazz...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > Hi Redhames, > > > Ok my form for city_suggestions looks like: > > > <% form_for @city_suggestion do |f| %> > > <%= f.error_messages %> > > > <p> > > <%= f.label :first_name %><br /> > > <%= f.text_field :first_name %> > > </p> > > <p> > > <%= f.label :last_name %><br /> > > <%= f.text_area :last_name %> > > </p> > > <p> > > <%= f.label :email %><br /> > > <%= f.text_field :email %> > > </p> > > <p> > > <%= f.label :city_name %><br /> > > <%= f.text_field :city_name %> > > </p> > > > <p> > > <%= f.submit ''Save'' %> > > </p> > > <% end %> > > > When I submit this, it saves this into the Suggestions table. However, > > the entry is not saved in the CitySuggestions table. Should I have a > > line in my CitySuggestions that explicitly saves the entry to this > > table as well? Or is RoR supposed to do this automatically? > > > On Sep 8, 5:46 am, radhames brito <rbri...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > well, from now on you can forget about the base model if you want to and > > use > > > everything as if they are 3 table and 3 models, do as you would normally > > > would with a simple model just dont use the base BaseSugesstions unless > > is > > > an admin and want to do something special. create scaffolds for > > > citySugesstions and BussinesSuggestion (by the way there is a typo en my > > > example the second class is supposed to be BussinesSuggestion not > > > BaseSuggestion) with free access to create and their own views and forms. > > > For adminsitration purposes and for your benefit create a basesugetion > > > controller for staticstics, un the base model you can use all kinds of > > > scopes to check and compare. > > > > On Tue, Sep 7, 2010 at 3:30 PM, Christian Fazzini < > > > > christian.fazz...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > Radhames, how do I go about creating the controllers for > > > > CitySuggestion and BusinessSuggestion? Can I use the scaffold > > > > generator for these two? > > > > > Or should I use the Suggestions controller to handle both? For > > > > example, where is the view/form to add new CitySuggestion? Should this > > > > be in the Suggestions controller? > > > > > I''m a bit confused here... > > > > > On Sep 8, 12:02 am, radhames brito <rbri...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > no you need single table inheritance > > > > > > is way better in your case , read a bit about STI, it lets you create > > one > > > > > table and one model and then inherit from that model > > > > > > list this > > > > > > class BaseSugesstions < ActiveRecord :: base > > > > > > attr_accessible first_name, last_name, email, city_name, > > business_name > > > > > > end > > > > > > then > > > > > > class citySugesstions < BaseSugesstions > > > > > > attr_accessible first_name, last_name, email, city_name > > > > > > end > > > > > > class BaseSugesstions < BaseSugesstions > > > > > > attr_accessible first_name, last_name, email, business_name > > > > > > end > > > > > > one table should on the database should have all the field defined in > > > > > BaseSugesstions > > > > > > On Tue, Sep 7, 2010 at 11:25 AM, Christian Fazzini < > > > > > > christian.fazz...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > > Hi Ar, > > > > > > > End-users can either be registered or non-registered users. Any > > type > > > > > > of user can suggest a business and a city. > > > > > > > When they suggest a city, they have to put in their first_name, > > > > > > last_name, email and city name. > > > > > > > When they suggest a business. They have to put in their first_name, > > > > > > last_name, email, business name and business address. > > > > > > > Initially, I had it working with two separate models: > > city_suggestion > > > > > > and business_suggestion. However, since both tables have fields > > that > > > > > > can be reused (i.e. first_name, last_name, email), I was thinking > > of > > > > > > using a polymorphic association. > > > > > > > I am not sure if this is the right approach or whether I should > > have > > > > > > just stuck with my original solution (i.e. two separate tables: > > > > > > city_suggestion and business_suggestion) > > > > > > > On Sep 7, 11:02 pm, Ar Chron <li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote: > > > > > > > Hmm... seems my interpretation of what you are attempting to do > > > > doesn''t > > > > > > > match very well with your unstated goals... You were asking > > whether > > > > the > > > > > > > suggestion model should be polymorphic... > > > > > > > > Sooo, what exactly is a suggestion in the context of your > > application > > > > > > > (what are your users doing)? > > > > > > > -- > > > > > > > Posted viahttp://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<rubyonrails-talk%2Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> > > <rubyonrails-talk%2Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org<rubyonrails-talk%252Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> > > > > > <rubyonrails-talk%2Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org<rubyonrails-talk%252Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> > > <rubyonrails-talk%252Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org<rubyonrails-talk%25252Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> > > > > > > > . > > > > > > For more options, visit this group at > > > > > >http://groups.google.com/group/rubyonrails-talk?hl=en. > > > > > -- > > > > 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@googlegroups.com > > . > > > > To unsubscribe from this group, send email to > > > > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org<rubyonrails-talk%2Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> > > <rubyonrails-talk%2Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org<rubyonrails-talk%252Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> > > > > > . > > > > For more options, visit this group at > > > >http://groups.google.com/group/rubyonrails-talk?hl=en. > > > -- > > 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > > To unsubscribe from this group, send email to > > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org<rubyonrails-talk%2Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> > > . > > For more options, visit this group at > >http://groups.google.com/group/rubyonrails-talk?hl=en.-- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Christian Fazzini wrote:> I thought you said I needed to scaffold the citysuggestion and > businesssuggestion? Scaffold generates controllers, views, and models > (if they already dont exist)? > > If I do rake db:migrate, it generates the tables in the db. Should I > remove the migration files that the scaffold generator generates > before doing rake db:migrate?Stop relying so much on the scaffold generator. You''ve probably gone beyond the point where it''s useful. Best, -- Marnen Laibow-Koser http://www.marnen.org marnen-sbuyVjPbboAdnm+yROfE0A@public.gmane.org -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Yes I know, I am just trying to understand how to implement this properly. It''s easy enough to rollback the migration and remove the respective migration files. However, I need to know whether I need controllers, models and views for citysuggestion and businesssuggestion On Sep 9, 9:46 pm, Marnen Laibow-Koser <li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> Christian Fazzini wrote: > > I thought you said I needed to scaffold the citysuggestion and > > businesssuggestion? Scaffold generates controllers, views, and models > > (if they already dont exist)? > > > If I do rake db:migrate, it generates the tables in the db. Should I > > remove the migration files that the scaffold generator generates > > before doing rake db:migrate? > > Stop relying so much on the scaffold generator. You''ve probably gone > beyond the point where it''s useful. > > Best, > -- > Marnen Laibow-Koserhttp://www.marnen.org > mar...-sbuyVjPbboAdnm+yROfE0A@public.gmane.org > -- > Posted viahttp://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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
sorry i forgot you use scaffold , here is the thing ill make a guide for this , from the migration step by step to the view create a table like this create_table :sugestions do |t| t.string first_name t.string last_name t.string email t.string business_name t.string business_address t.string city_name t.string type end no more tables are needed create a model Sugestion , (singular) as normal it should inherit from active record base like this class Sugestion < ActiveRecord::Base attr_accessible : first_name,last_name, email, business_name, business_address, city_name then create the tu other model that inherit from Sugestion, note that is they is a capital letter in the model name rails will put an underscore like this city_sugestions_controller class CitySugestion < ActiveRecord::Base attr_accessible : first_name,last_name, email, city_name and another class bussinessSugestion < ActiveRecord::Base attr_accessible : first_name,last_name, email,business_name, business_address note i think type should not be available with mass assignment. then create the controllers for the 2 sugestions classes city_sugestions_controller and bussiness_sugestions_controller from here one this controller will never notice you have only one table they will behave as if you had 2 different tables in the db in you views just refer to @bussinesssugestions and it will be scoped thanks to the type field that active record will automaticly use then you save an object of either class. Dont try to access the type field using @citysuggestion.type or @suggestion.type as type is a ruby method and will be called instead of the table field, use @sugestion[:type] , the other fields can be called as normal. If you want to handle the sugestion class directly you can create a sugestions_controller, it its corresponding viwes for it and have a named scope that filter each type. Dont be afraid to keep asking if you are still confuse and keep in mind that in most case, people are not specting that you would use scaffolds every time since scaffold are more like a learning tool that an actual way of doing things. if you want to use scaffold anyway you can create the scaffold and skip creating the migrations with script/generate scaffold --skip-migrations On Thu, Sep 9, 2010 at 9:52 AM, Christian Fazzini < christian.fazzini-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Yes I know, I am just trying to understand how to implement this > properly. It''s easy enough to rollback the migration and remove the > respective migration files. However, I need to know whether I need > controllers, models and views for citysuggestion and > businesssuggestion > > On Sep 9, 9:46 pm, Marnen Laibow-Koser <li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote: > > Christian Fazzini wrote: > > > I thought you said I needed to scaffold the citysuggestion and > > > businesssuggestion? Scaffold generates controllers, views, and models > > > (if they already dont exist)? > > > > > If I do rake db:migrate, it generates the tables in the db. Should I > > > remove the migration files that the scaffold generator generates > > > before doing rake db:migrate? > > > > Stop relying so much on the scaffold generator. You''ve probably gone > > beyond the point where it''s useful. > > > > Best, > > -- > > Marnen Laibow-Koserhttp://www.marnen.org > > mar...-sbuyVjPbboAdnm+yROfE0A@public.gmane.org > > -- > > Posted viahttp://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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org<rubyonrails-talk%2Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> > . > For more options, visit this group at > http://groups.google.com/group/rubyonrails-talk?hl=en. > >-- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Thanks Radhames. Ok I got it up to there. I am assuming since we are creating controllers for city_suggestions and business_suggestions, we will also need to create view for them respectively? i.e. /app/views/ city_suggestions and /app/views/business_suggestions right? I appreciate your patience and thorough explanation regarding STI. Once I grasp this concept properly, I can apply the same knowledge on other cases :-) On Sep 9, 10:26 pm, radhames brito <rbri...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> sorry i forgot you use scaffold , here is the thing ill make a guide for > this , from the migration step by step to the view > > create a table like this > > create_table :sugestions do |t| > t.string first_name > t.string last_name > t.string email > t.string business_name > t.string business_address > t.string city_name > t.string type > end > > no more tables are needed > > create a model > > Sugestion , (singular) as normal it should inherit from active record base > like this > > class Sugestion < ActiveRecord::Base > > attr_accessible : first_name,last_name, email, business_name, > business_address, city_name > > then create the tu other model that inherit from Sugestion, note that is > they is a capital letter in the model name rails will put an underscore like > this city_sugestions_controller > > class CitySugestion < ActiveRecord::Base > > attr_accessible : first_name,last_name, email, city_name > > and another > > class bussinessSugestion < ActiveRecord::Base > > attr_accessible : first_name,last_name, email,business_name, > business_address > > note i think type should not be available with mass assignment. > > then create the controllers for the 2 sugestions classes > > city_sugestions_controller > > and > > bussiness_sugestions_controller > > from here one this controller will never notice you have only one table they > will behave as if you had 2 different tables in the db > > in you views just refer to @bussinesssugestions and it will be scoped thanks > to the type field that active record will automaticly use then you save an > object of either class. Dont try to access the type field using > @citysuggestion.type or @suggestion.type as type is a ruby method and will > be called instead of > the table field, use @sugestion[:type] , the other fields can be called as > normal. > > If you want to handle the sugestion class directly you can create a > sugestions_controller, it its corresponding viwes for it and have a named > scope that filter each type. > > Dont be afraid to keep asking if you are still confuse and keep in mind that > in most case, people are not specting that you would use scaffolds every > time since scaffold are more like a learning tool that an actual way of > doing things. > > if you want to use scaffold anyway you can create the scaffold and skip > creating the migrations with > > script/generate scaffold --skip-migrations > > On Thu, Sep 9, 2010 at 9:52 AM, Christian Fazzini < > > christian.fazz...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > Yes I know, I am just trying to understand how to implement this > > properly. It''s easy enough to rollback the migration and remove the > > respective migration files. However, I need to know whether I need > > controllers, models and views for citysuggestion and > > businesssuggestion > > > On Sep 9, 9:46 pm, Marnen Laibow-Koser <li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote: > > > Christian Fazzini wrote: > > > > I thought you said I needed to scaffold the citysuggestion and > > > > businesssuggestion? Scaffold generates controllers, views, and models > > > > (if they already dont exist)? > > > > > If I do rake db:migrate, it generates the tables in the db. Should I > > > > remove the migration files that the scaffold generator generates > > > > before doing rake db:migrate? > > > > Stop relying so much on the scaffold generator. You''ve probably gone > > > beyond the point where it''s useful. > > > > Best, > > > -- > > > Marnen Laibow-Koserhttp://www.marnen.org > > > mar...-sbuyVjPbboAdnm+yROfE0A@public.gmane.org > > > -- > > > Posted viahttp://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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > > To unsubscribe from this group, send email to > > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org<rubyonrails-talk%2Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> > > . > > For more options, visit this group at > >http://groups.google.com/group/rubyonrails-talk?hl=en.-- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
yes thats rigth, everything will behave as if you had 2 tables , is normal RoR from now on. yes dont be afraid to ask. On Thu, Sep 9, 2010 at 1:06 PM, Christian Fazzini < christian.fazzini-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Thanks Radhames. Ok I got it up to there. I am assuming since we are > creating controllers for city_suggestions and business_suggestions, we > will also need to create view for them respectively? i.e. /app/views/ > city_suggestions and /app/views/business_suggestions right? > > I appreciate your patience and thorough explanation regarding STI. > Once I grasp this concept properly, I can apply the same knowledge on > other cases :-) > > On Sep 9, 10:26 pm, radhames brito <rbri...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > sorry i forgot you use scaffold , here is the thing ill make a guide for > > this , from the migration step by step to the view > > > > create a table like this > > > > create_table :sugestions do |t| > > t.string first_name > > t.string last_name > > t.string email > > t.string business_name > > t.string business_address > > t.string city_name > > t.string type > > end > > > > no more tables are needed > > > > create a model > > > > Sugestion , (singular) as normal it should inherit from active record > base > > like this > > > > class Sugestion < ActiveRecord::Base > > > > attr_accessible : first_name,last_name, email, business_name, > > business_address, city_name > > > > then create the tu other model that inherit from Sugestion, note that is > > they is a capital letter in the model name rails will put an underscore > like > > this city_sugestions_controller > > > > class CitySugestion < ActiveRecord::Base > > > > attr_accessible : first_name,last_name, email, city_name > > > > and another > > > > class bussinessSugestion < ActiveRecord::Base > > > > attr_accessible : first_name,last_name, email,business_name, > > business_address > > > > note i think type should not be available with mass assignment. > > > > then create the controllers for the 2 sugestions classes > > > > city_sugestions_controller > > > > and > > > > bussiness_sugestions_controller > > > > from here one this controller will never notice you have only one table > they > > will behave as if you had 2 different tables in the db > > > > in you views just refer to @bussinesssugestions and it will be scoped > thanks > > to the type field that active record will automaticly use then you save > an > > object of either class. Dont try to access the type field using > > @citysuggestion.type or @suggestion.type as type is a ruby method and > will > > be called instead of > > the table field, use @sugestion[:type] , the other fields can be called > as > > normal. > > > > If you want to handle the sugestion class directly you can create a > > sugestions_controller, it its corresponding viwes for it and have a named > > scope that filter each type. > > > > Dont be afraid to keep asking if you are still confuse and keep in mind > that > > in most case, people are not specting that you would use scaffolds every > > time since scaffold are more like a learning tool that an actual way of > > doing things. > > > > if you want to use scaffold anyway you can create the scaffold and skip > > creating the migrations with > > > > script/generate scaffold --skip-migrations > > > > On Thu, Sep 9, 2010 at 9:52 AM, Christian Fazzini < > > > > christian.fazz...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > Yes I know, I am just trying to understand how to implement this > > > properly. It''s easy enough to rollback the migration and remove the > > > respective migration files. However, I need to know whether I need > > > controllers, models and views for citysuggestion and > > > businesssuggestion > > > > > On Sep 9, 9:46 pm, Marnen Laibow-Koser <li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote: > > > > Christian Fazzini wrote: > > > > > I thought you said I needed to scaffold the citysuggestion and > > > > > businesssuggestion? Scaffold generates controllers, views, and > models > > > > > (if they already dont exist)? > > > > > > > If I do rake db:migrate, it generates the tables in the db. Should > I > > > > > remove the migration files that the scaffold generator generates > > > > > before doing rake db:migrate? > > > > > > Stop relying so much on the scaffold generator. You''ve probably gone > > > > beyond the point where it''s useful. > > > > > > Best, > > > > -- > > > > Marnen Laibow-Koserhttp://www.marnen.org > > > > mar...-sbuyVjPbboAdnm+yROfE0A@public.gmane.org > > > > -- > > > > Posted viahttp://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<rubyonrails-talk%2Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> > <rubyonrails-talk%2Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org<rubyonrails-talk%252Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> > > > > > . > > > For more options, visit this group at > > >http://groups.google.com/group/rubyonrails-talk?hl=en. > > -- > 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org<rubyonrails-talk%2Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> > . > For more options, visit this group at > http://groups.google.com/group/rubyonrails-talk?hl=en. > >-- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Redhames, got it thanks! Have tested this and now seems to work. Even the type field is put in automatically when the form submits. Is this normal that the type field saves as "CitySuggestion" and "BusinessSuggestion" respectively? Can I change the way it saves, as "city" or "business", instead? Can we talk about the design factor for this. I realise the potential of STI''s now. However, lets assume this scenario. Ive got user and product. A user can leave comments, like, upload products. These are called interactions. On a product page, I need to display the product and all comments for the product. I also have a user page with a section that displays all the users recent interactions, sorted by the created_at date. I was thinking of using an STI for this, with something like: class Interaction < ActiveRecord::Base attr_accessible :user_id, :product_id, :comment, :ip_address, :type ---------- class Comment < Suggestion attr_accessible :user_id, :product_id, :comment ---------- class Upload < Suggestion attr_accessible :user_id, :product_id, :ip_address ---------- class Like < Suggestion attr_accessible :user_id, :product_id However, I was also considering using a polymorphic behavior. Or in your opinion, would an STI be more suitable for this? On Sep 10, 3:06 am, radhames brito <rbri...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> yes thats rigth, everything will behave as if you had 2 tables , is normal > RoR from now on. > > yes dont be afraid to ask. > > On Thu, Sep 9, 2010 at 1:06 PM, Christian Fazzini < > > christian.fazz...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > Thanks Radhames. Ok I got it up to there. I am assuming since we are > > creating controllers for city_suggestions and business_suggestions, we > > will also need to create view for them respectively? i.e. /app/views/ > > city_suggestions and /app/views/business_suggestions right? > > > I appreciate your patience and thorough explanation regarding STI. > > Once I grasp this concept properly, I can apply the same knowledge on > > other cases :-) > > > On Sep 9, 10:26 pm, radhames brito <rbri...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > sorry i forgot you use scaffold , here is the thing ill make a guide for > > > this , from the migration step by step to the view > > > > create a table like this > > > > create_table :sugestions do |t| > > > t.string first_name > > > t.string last_name > > > t.string email > > > t.string business_name > > > t.string business_address > > > t.string city_name > > > t.string type > > > end > > > > no more tables are needed > > > > create a model > > > > Sugestion , (singular) as normal it should inherit from active record > > base > > > like this > > > > class Sugestion < ActiveRecord::Base > > > > attr_accessible : first_name,last_name, email, business_name, > > > business_address, city_name > > > > then create the tu other model that inherit from Sugestion, note that is > > > they is a capital letter in the model name rails will put an underscore > > like > > > this city_sugestions_controller > > > > class CitySugestion < ActiveRecord::Base > > > > attr_accessible : first_name,last_name, email, city_name > > > > and another > > > > class bussinessSugestion < ActiveRecord::Base > > > > attr_accessible : first_name,last_name, email,business_name, > > > business_address > > > > note i think type should not be available with mass assignment. > > > > then create the controllers for the 2 sugestions classes > > > > city_sugestions_controller > > > > and > > > > bussiness_sugestions_controller > > > > from here one this controller will never notice you have only one table > > they > > > will behave as if you had 2 different tables in the db > > > > in you views just refer to @bussinesssugestions and it will be scoped > > thanks > > > to the type field that active record will automaticly use then you save > > an > > > object of either class. Dont try to access the type field using > > > @citysuggestion.type or @suggestion.type as type is a ruby method and > > will > > > be called instead of > > > the table field, use @sugestion[:type] , the other fields can be called > > as > > > normal. > > > > If you want to handle the sugestion class directly you can create a > > > sugestions_controller, it its corresponding viwes for it and have a named > > > scope that filter each type. > > > > Dont be afraid to keep asking if you are still confuse and keep in mind > > that > > > in most case, people are not specting that you would use scaffolds every > > > time since scaffold are more like a learning tool that an actual way of > > > doing things. > > > > if you want to use scaffold anyway you can create the scaffold and skip > > > creating the migrations with > > > > script/generate scaffold --skip-migrations > > > > On Thu, Sep 9, 2010 at 9:52 AM, Christian Fazzini < > > > > christian.fazz...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > Yes I know, I am just trying to understand how to implement this > > > > properly. It''s easy enough to rollback the migration and remove the > > > > respective migration files. However, I need to know whether I need > > > > controllers, models and views for citysuggestion and > > > > businesssuggestion > > > > > On Sep 9, 9:46 pm, Marnen Laibow-Koser <li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote: > > > > > Christian Fazzini wrote: > > > > > > I thought you said I needed to scaffold the citysuggestion and > > > > > > businesssuggestion? Scaffold generates controllers, views, and > > models > > > > > > (if they already dont exist)? > > > > > > > If I do rake db:migrate, it generates the tables in the db. Should > > I > > > > > > remove the migration files that the scaffold generator generates > > > > > > before doing rake db:migrate? > > > > > > Stop relying so much on the scaffold generator. You''ve probably gone > > > > > beyond the point where it''s useful. > > > > > > Best, > > > > > -- > > > > > Marnen Laibow-Koserhttp://www.marnen.org > > > > > mar...-sbuyVjPbboAdnm+yROfE0A@public.gmane.org > > > > > -- > > > > > Posted viahttp://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@googlegroups.com > > . > > > > To unsubscribe from this group, send email to > > > > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org<rubyonrails-talk%2Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> > > <rubyonrails-talk%2Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org<rubyonrails-talk%252Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> > > > > > . > > > > For more options, visit this group at > > > >http://groups.google.com/group/rubyonrails-talk?hl=en. > > > -- > > 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > > To unsubscribe from this group, send email to > > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org<rubyonrails-talk%2Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> > > . > > For more options, visit this group at > >http://groups.google.com/group/rubyonrails-talk?hl=en.-- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
dont touch the type fields. If you have a child model that you have to attach to different models use polymorphic associations. if you have 2 models with a few different fields use STI. if it guess too clomplex is means you choose wrong and you were so suppose to use the other kind of association. thi the case you are saying you dont need any of those, only a comment model that belongs to product and to user like this class user has_many comments ## the table should not have a comment_id field has_many products :through =>comments class product has_many comments ## the table should not have a comment_id field has_many users :through =>comments class comment belongs_to :user belongs_to :product the coment migration should be like this create_table :comments do |t| t.integer :user_id t.integer :product_id t.content t.timestamp On Thu, Sep 9, 2010 at 6:09 PM, Christian Fazzini < christian.fazzini-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Redhames, got it thanks! Have tested this and now seems to work. Even > the type field is put in automatically when the form submits. > > Is this normal that the type field saves as "CitySuggestion" and > "BusinessSuggestion" respectively? Can I change the way it saves, as > "city" or "business", instead? > > Can we talk about the design factor for this. I realise the potential > of STI''s now. However, lets assume this scenario. > > Ive got user and product. A user can leave comments, like, upload > products. These are called interactions. On a product page, I need to > display the product and all comments for the product. I also have a > user page with a section that displays all the users recent > interactions, sorted by the created_at date. > > I was thinking of using an STI for this, with something like: > > class Interaction < ActiveRecord::Base > attr_accessible :user_id, :product_id, :comment, :ip_address, :type > > ---------- > class Comment < Suggestion > attr_accessible :user_id, :product_id, :comment > > ---------- > class Upload < Suggestion > attr_accessible :user_id, :product_id, :ip_address > > ---------- > class Like < Suggestion > attr_accessible :user_id, :product_id > > However, I was also considering using a polymorphic behavior. Or in > your opinion, would an STI be more suitable for this? > > On Sep 10, 3:06 am, radhames brito <rbri...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > yes thats rigth, everything will behave as if you had 2 tables , is > normal > > RoR from now on. > > > > yes dont be afraid to ask. > > > > On Thu, Sep 9, 2010 at 1:06 PM, Christian Fazzini < > > > > christian.fazz...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > Thanks Radhames. Ok I got it up to there. I am assuming since we are > > > creating controllers for city_suggestions and business_suggestions, we > > > will also need to create view for them respectively? i.e. /app/views/ > > > city_suggestions and /app/views/business_suggestions right? > > > > > I appreciate your patience and thorough explanation regarding STI. > > > Once I grasp this concept properly, I can apply the same knowledge on > > > other cases :-) > > > > > On Sep 9, 10:26 pm, radhames brito <rbri...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > sorry i forgot you use scaffold , here is the thing ill make a guide > for > > > > this , from the migration step by step to the view > > > > > > create a table like this > > > > > > create_table :sugestions do |t| > > > > t.string first_name > > > > t.string last_name > > > > t.string email > > > > t.string business_name > > > > t.string business_address > > > > t.string city_name > > > > t.string type > > > > end > > > > > > no more tables are needed > > > > > > create a model > > > > > > Sugestion , (singular) as normal it should inherit from active record > > > base > > > > like this > > > > > > class Sugestion < ActiveRecord::Base > > > > > > attr_accessible : first_name,last_name, email, business_name, > > > > business_address, city_name > > > > > > then create the tu other model that inherit from Sugestion, note that > is > > > > they is a capital letter in the model name rails will put an > underscore > > > like > > > > this city_sugestions_controller > > > > > > class CitySugestion < ActiveRecord::Base > > > > > > attr_accessible : first_name,last_name, email, city_name > > > > > > and another > > > > > > class bussinessSugestion < ActiveRecord::Base > > > > > > attr_accessible : first_name,last_name, email,business_name, > > > > business_address > > > > > > note i think type should not be available with mass assignment. > > > > > > then create the controllers for the 2 sugestions classes > > > > > > city_sugestions_controller > > > > > > and > > > > > > bussiness_sugestions_controller > > > > > > from here one this controller will never notice you have only one > table > > > they > > > > will behave as if you had 2 different tables in the db > > > > > > in you views just refer to @bussinesssugestions and it will be scoped > > > thanks > > > > to the type field that active record will automaticly use then you > save > > > an > > > > object of either class. Dont try to access the type field using > > > > @citysuggestion.type or @suggestion.type as type is a ruby method and > > > will > > > > be called instead of > > > > the table field, use @sugestion[:type] , the other fields can be > called > > > as > > > > normal. > > > > > > If you want to handle the sugestion class directly you can create a > > > > sugestions_controller, it its corresponding viwes for it and have a > named > > > > scope that filter each type. > > > > > > Dont be afraid to keep asking if you are still confuse and keep in > mind > > > that > > > > in most case, people are not specting that you would use scaffolds > every > > > > time since scaffold are more like a learning tool that an actual way > of > > > > doing things. > > > > > > if you want to use scaffold anyway you can create the scaffold and > skip > > > > creating the migrations with > > > > > > script/generate scaffold --skip-migrations > > > > > > On Thu, Sep 9, 2010 at 9:52 AM, Christian Fazzini < > > > > > > christian.fazz...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > Yes I know, I am just trying to understand how to implement this > > > > > properly. It''s easy enough to rollback the migration and remove the > > > > > respective migration files. However, I need to know whether I need > > > > > controllers, models and views for citysuggestion and > > > > > businesssuggestion > > > > > > > On Sep 9, 9:46 pm, Marnen Laibow-Koser <li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> > wrote: > > > > > > Christian Fazzini wrote: > > > > > > > I thought you said I needed to scaffold the citysuggestion and > > > > > > > businesssuggestion? Scaffold generates controllers, views, and > > > models > > > > > > > (if they already dont exist)? > > > > > > > > > If I do rake db:migrate, it generates the tables in the db. > Should > > > I > > > > > > > remove the migration files that the scaffold generator > generates > > > > > > > before doing rake db:migrate? > > > > > > > > Stop relying so much on the scaffold generator. You''ve probably > gone > > > > > > beyond the point where it''s useful. > > > > > > > > Best, > > > > > > -- > > > > > > Marnen Laibow-Koserhttp://www.marnen.org > > > > > > mar...-sbuyVjPbboAdnm+yROfE0A@public.gmane.org > > > > > > -- > > > > > > Posted viahttp://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<rubyonrails-talk%2Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> > <rubyonrails-talk%2Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org<rubyonrails-talk%252Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> > > > > > <rubyonrails-talk%2Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org<rubyonrails-talk%252Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> > <rubyonrails-talk%252Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org<rubyonrails-talk%25252Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> > > > > > > > > > . > > > > > For more options, visit this group at > > > > >http://groups.google.com/group/rubyonrails-talk?hl=en. > > > > > -- > > > 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<rubyonrails-talk%2Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> > <rubyonrails-talk%2Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org<rubyonrails-talk%252Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> > > > > > . > > > For more options, visit this group at > > >http://groups.google.com/group/rubyonrails-talk?hl=en. > > -- > 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org<rubyonrails-talk%2Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> > . > For more options, visit this group at > http://groups.google.com/group/rubyonrails-talk?hl=en. > >-- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
watch this http://railscasts.com/episodes/47-two-many-to-many On Thu, Sep 9, 2010 at 9:16 PM, radhames brito <rbritom-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> dont touch the type fields. > > If you have a child model that you have to attach to different models use > polymorphic associations. > if you have 2 models with a few different fields use STI. > > if it guess too clomplex is means you choose wrong and you were so suppose > to use the other kind of association. > > > thi the case you are saying you dont need any of those, only a comment > model that belongs to product and to user like this > > class user > has_many comments ## the table should not have > a comment_id field > has_many products :through =>comments > > class product > has_many comments ## the table should not have > a comment_id field > has_many users :through =>comments > > class comment > belongs_to :user > belongs_to :product > > > the coment migration should be like this > > create_table :comments do |t| > t.integer :user_id > t.integer :product_id > t.content > t.timestamp > > > > > > > > > On Thu, Sep 9, 2010 at 6:09 PM, Christian Fazzini < > christian.fazzini-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > >> Redhames, got it thanks! Have tested this and now seems to work. Even >> the type field is put in automatically when the form submits. >> >> Is this normal that the type field saves as "CitySuggestion" and >> "BusinessSuggestion" respectively? Can I change the way it saves, as >> "city" or "business", instead? >> >> Can we talk about the design factor for this. I realise the potential >> of STI''s now. However, lets assume this scenario. >> >> Ive got user and product. A user can leave comments, like, upload >> products. These are called interactions. On a product page, I need to >> display the product and all comments for the product. I also have a >> user page with a section that displays all the users recent >> interactions, sorted by the created_at date. >> >> I was thinking of using an STI for this, with something like: >> >> class Interaction < ActiveRecord::Base >> attr_accessible :user_id, :product_id, :comment, :ip_address, :type >> >> ---------- >> class Comment < Suggestion >> attr_accessible :user_id, :product_id, :comment >> >> ---------- >> class Upload < Suggestion >> attr_accessible :user_id, :product_id, :ip_address >> >> ---------- >> class Like < Suggestion >> attr_accessible :user_id, :product_id >> >> However, I was also considering using a polymorphic behavior. Or in >> your opinion, would an STI be more suitable for this? >> >> On Sep 10, 3:06 am, radhames brito <rbri...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: >> > yes thats rigth, everything will behave as if you had 2 tables , is >> normal >> > RoR from now on. >> > >> > yes dont be afraid to ask. >> > >> > On Thu, Sep 9, 2010 at 1:06 PM, Christian Fazzini < >> > >> > christian.fazz...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: >> > > Thanks Radhames. Ok I got it up to there. I am assuming since we are >> > > creating controllers for city_suggestions and business_suggestions, we >> > > will also need to create view for them respectively? i.e. /app/views/ >> > > city_suggestions and /app/views/business_suggestions right? >> > >> > > I appreciate your patience and thorough explanation regarding STI. >> > > Once I grasp this concept properly, I can apply the same knowledge on >> > > other cases :-) >> > >> > > On Sep 9, 10:26 pm, radhames brito <rbri...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: >> > > > sorry i forgot you use scaffold , here is the thing ill make a guide >> for >> > > > this , from the migration step by step to the view >> > >> > > > create a table like this >> > >> > > > create_table :sugestions do |t| >> > > > t.string first_name >> > > > t.string last_name >> > > > t.string email >> > > > t.string business_name >> > > > t.string business_address >> > > > t.string city_name >> > > > t.string type >> > > > end >> > >> > > > no more tables are needed >> > >> > > > create a model >> > >> > > > Sugestion , (singular) as normal it should inherit from active >> record >> > > base >> > > > like this >> > >> > > > class Sugestion < ActiveRecord::Base >> > >> > > > attr_accessible : first_name,last_name, email, business_name, >> > > > business_address, city_name >> > >> > > > then create the tu other model that inherit from Sugestion, note >> that is >> > > > they is a capital letter in the model name rails will put an >> underscore >> > > like >> > > > this city_sugestions_controller >> > >> > > > class CitySugestion < ActiveRecord::Base >> > >> > > > attr_accessible : first_name,last_name, email, city_name >> > >> > > > and another >> > >> > > > class bussinessSugestion < ActiveRecord::Base >> > >> > > > attr_accessible : first_name,last_name, email,business_name, >> > > > business_address >> > >> > > > note i think type should not be available with mass assignment. >> > >> > > > then create the controllers for the 2 sugestions classes >> > >> > > > city_sugestions_controller >> > >> > > > and >> > >> > > > bussiness_sugestions_controller >> > >> > > > from here one this controller will never notice you have only one >> table >> > > they >> > > > will behave as if you had 2 different tables in the db >> > >> > > > in you views just refer to @bussinesssugestions and it will be >> scoped >> > > thanks >> > > > to the type field that active record will automaticly use then you >> save >> > > an >> > > > object of either class. Dont try to access the type field using >> > > > @citysuggestion.type or @suggestion.type as type is a ruby method >> and >> > > will >> > > > be called instead of >> > > > the table field, use @sugestion[:type] , the other fields can be >> called >> > > as >> > > > normal. >> > >> > > > If you want to handle the sugestion class directly you can create a >> > > > sugestions_controller, it its corresponding viwes for it and have a >> named >> > > > scope that filter each type. >> > >> > > > Dont be afraid to keep asking if you are still confuse and keep in >> mind >> > > that >> > > > in most case, people are not specting that you would use scaffolds >> every >> > > > time since scaffold are more like a learning tool that an actual way >> of >> > > > doing things. >> > >> > > > if you want to use scaffold anyway you can create the scaffold and >> skip >> > > > creating the migrations with >> > >> > > > script/generate scaffold --skip-migrations >> > >> > > > On Thu, Sep 9, 2010 at 9:52 AM, Christian Fazzini < >> > >> > > > christian.fazz...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: >> > > > > Yes I know, I am just trying to understand how to implement this >> > > > > properly. It''s easy enough to rollback the migration and remove >> the >> > > > > respective migration files. However, I need to know whether I need >> > > > > controllers, models and views for citysuggestion and >> > > > > businesssuggestion >> > >> > > > > On Sep 9, 9:46 pm, Marnen Laibow-Koser <li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> >> wrote: >> > > > > > Christian Fazzini wrote: >> > > > > > > I thought you said I needed to scaffold the citysuggestion and >> > > > > > > businesssuggestion? Scaffold generates controllers, views, and >> > > models >> > > > > > > (if they already dont exist)? >> > >> > > > > > > If I do rake db:migrate, it generates the tables in the db. >> Should >> > > I >> > > > > > > remove the migration files that the scaffold generator >> generates >> > > > > > > before doing rake db:migrate? >> > >> > > > > > Stop relying so much on the scaffold generator. You''ve probably >> gone >> > > > > > beyond the point where it''s useful. >> > >> > > > > > Best, >> > > > > > -- >> > > > > > Marnen Laibow-Koserhttp://www.marnen.org >> > > > > > mar...-sbuyVjPbboAdnm+yROfE0A@public.gmane.org >> > > > > > -- >> > > > > > Posted viahttp://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<rubyonrails-talk%2Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> >> <rubyonrails-talk%2Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org<rubyonrails-talk%252Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> >> > >> > > <rubyonrails-talk%2Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org<rubyonrails-talk%252Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> >> <rubyonrails-talk%252Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org<rubyonrails-talk%25252Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> >> > >> > >> > > > > . >> > > > > For more options, visit this group at >> > > > >http://groups.google.com/group/rubyonrails-talk?hl=en. >> > >> > > -- >> > > 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org >> > > To unsubscribe from this group, send email to >> > > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org<rubyonrails-talk%2Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> >> <rubyonrails-talk%2Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org<rubyonrails-talk%252Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> >> > >> > > . >> > > For more options, visit this group at >> > >http://groups.google.com/group/rubyonrails-talk?hl=en. >> >> -- >> 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org >> To unsubscribe from this group, send email to >> rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org<rubyonrails-talk%2Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> >> . >> For more options, visit this group at >> http://groups.google.com/group/rubyonrails-talk?hl=en. >> >> >-- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Hi Radhames. Yea, the case you mention above would work. Except, since you are suggesting I have a comment table on its own. Then I would need to have a like and upload table on its own as well. If I needed to list recent interactions (to list down a user feed), I would have to union join the comment, like and upload tables. If I had one table called interactions, I could just query this ONE table and add a where clause (user_id =12, for example) and sort by created_at. Performance wise, it is better then having to union join 3 other tables together... The question is now, whether this should be done using a polymorphic association or STI On Sep 10, 8:16 am, radhames brito <rbri...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> dont touch the type fields. > > If you have a child model that you have to attach to different models use > polymorphic associations. > if you have 2 models with a few different fields use STI. > > if it guess too clomplex is means you choose wrong and you were so suppose > to use the other kind of association. > > thi the case you are saying you dont need any of those, only a comment model > that belongs to product and to user like this > > class user > has_many comments ## the table should not have > a comment_id field > has_many products :through =>comments > > class product > has_many comments ## the table should not have > a comment_id field > has_many users :through =>comments > > class comment > belongs_to :user > belongs_to :product > > the coment migration should be like this > > create_table :comments do |t| > t.integer :user_id > t.integer :product_id > t.content > t.timestamp > > On Thu, Sep 9, 2010 at 6:09 PM, Christian Fazzini < > > christian.fazz...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > Redhames, got it thanks! Have tested this and now seems to work. Even > > the type field is put in automatically when the form submits. > > > Is this normal that the type field saves as "CitySuggestion" and > > "BusinessSuggestion" respectively? Can I change the way it saves, as > > "city" or "business", instead? > > > Can we talk about the design factor for this. I realise the potential > > of STI''s now. However, lets assume this scenario. > > > Ive got user and product. A user can leave comments, like, upload > > products. These are called interactions. On a product page, I need to > > display the product and all comments for the product. I also have a > > user page with a section that displays all the users recent > > interactions, sorted by the created_at date. > > > I was thinking of using an STI for this, with something like: > > > class Interaction < ActiveRecord::Base > > attr_accessible :user_id, :product_id, :comment, :ip_address, :type > > > ---------- > > class Comment < Suggestion > > attr_accessible :user_id, :product_id, :comment > > > ---------- > > class Upload < Suggestion > > attr_accessible :user_id, :product_id, :ip_address > > > ---------- > > class Like < Suggestion > > attr_accessible :user_id, :product_id > > > However, I was also considering using a polymorphic behavior. Or in > > your opinion, would an STI be more suitable for this? > > > On Sep 10, 3:06 am, radhames brito <rbri...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > yes thats rigth, everything will behave as if you had 2 tables , is > > normal > > > RoR from now on. > > > > yes dont be afraid to ask. > > > > On Thu, Sep 9, 2010 at 1:06 PM, Christian Fazzini < > > > > christian.fazz...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > Thanks Radhames. Ok I got it up to there. I am assuming since we are > > > > creating controllers for city_suggestions and business_suggestions, we > > > > will also need to create view for them respectively? i.e. /app/views/ > > > > city_suggestions and /app/views/business_suggestions right? > > > > > I appreciate your patience and thorough explanation regarding STI. > > > > Once I grasp this concept properly, I can apply the same knowledge on > > > > other cases :-) > > > > > On Sep 9, 10:26 pm, radhames brito <rbri...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > sorry i forgot you use scaffold , here is the thing ill make a guide > > for > > > > > this , from the migration step by step to the view > > > > > > create a table like this > > > > > > create_table :sugestions do |t| > > > > > t.string first_name > > > > > t.string last_name > > > > > t.string email > > > > > t.string business_name > > > > > t.string business_address > > > > > t.string city_name > > > > > t.string type > > > > > end > > > > > > no more tables are needed > > > > > > create a model > > > > > > Sugestion , (singular) as normal it should inherit from active record > > > > base > > > > > like this > > > > > > class Sugestion < ActiveRecord::Base > > > > > > attr_accessible : first_name,last_name, email, business_name, > > > > > business_address, city_name > > > > > > then create the tu other model that inherit from Sugestion, note that > > is > > > > > they is a capital letter in the model name rails will put an > > underscore > > > > like > > > > > this city_sugestions_controller > > > > > > class CitySugestion < ActiveRecord::Base > > > > > > attr_accessible : first_name,last_name, email, city_name > > > > > > and another > > > > > > class bussinessSugestion < ActiveRecord::Base > > > > > > attr_accessible : first_name,last_name, email,business_name, > > > > > business_address > > > > > > note i think type should not be available with mass assignment. > > > > > > then create the controllers for the 2 sugestions classes > > > > > > city_sugestions_controller > > > > > > and > > > > > > bussiness_sugestions_controller > > > > > > from here one this controller will never notice you have only one > > table > > > > they > > > > > will behave as if you had 2 different tables in the db > > > > > > in you views just refer to @bussinesssugestions and it will be scoped > > > > thanks > > > > > to the type field that active record will automaticly use then you > > save > > > > an > > > > > object of either class. Dont try to access the type field using > > > > > @citysuggestion.type or @suggestion.type as type is a ruby method and > > > > will > > > > > be called instead of > > > > > the table field, use @sugestion[:type] , the other fields can be > > called > > > > as > > > > > normal. > > > > > > If you want to handle the sugestion class directly you can create a > > > > > sugestions_controller, it its corresponding viwes for it and have a > > named > > > > > scope that filter each type. > > > > > > Dont be afraid to keep asking if you are still confuse and keep in > > mind > > > > that > > > > > in most case, people are not specting that you would use scaffolds > > every > > > > > time since scaffold are more like a learning tool that an actual way > > of > > > > > doing things. > > > > > > if you want to use scaffold anyway you can create the scaffold and > > skip > > > > > creating the migrations with > > > > > > script/generate scaffold --skip-migrations > > > > > > On Thu, Sep 9, 2010 at 9:52 AM, Christian Fazzini < > > > > > > christian.fazz...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > > Yes I know, I am just trying to understand how to implement this > > > > > > properly. It''s easy enough to rollback the migration and remove the > > > > > > respective migration files. However, I need to know whether I need > > > > > > controllers, models and views for citysuggestion and > > > > > > businesssuggestion > > > > > > > On Sep 9, 9:46 pm, Marnen Laibow-Koser <li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> > > wrote: > > > > > > > Christian Fazzini wrote: > > > > > > > > I thought you said I needed to scaffold the citysuggestion and > > > > > > > > businesssuggestion? Scaffold generates controllers, views, and > > > > models > > > > > > > > (if they already dont exist)? > > > > > > > > > If I do rake db:migrate, it generates the tables in the db. > > Should > > > > I > > > > > > > > remove the migration files that the scaffold generator > > generates > > > > > > > > before doing rake db:migrate? > > > > > > > > Stop relying so much on the scaffold generator. You''ve probably > > gone > > > > > > > beyond the point where it''s useful. > > > > > > > > Best, > > > > > > > -- > > > > > > > Marnen Laibow-Koserhttp://www.marnen.org > > > > > > > mar...-sbuyVjPbboAdnm+yROfE0A@public.gmane.org > > > > > > > -- > > > > > > > Posted viahttp://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<rubyonrails-talk%2Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> > > <rubyonrails-talk%2Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org<rubyonrails-talk%252Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> > > > > > <rubyonrails-talk%2Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org<rubyonrails-talk%252Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> > > <rubyonrails-talk%252Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org<rubyonrails-talk%25252Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> > > > > > > > . > > > > > > For more options, visit this group at > > > > > >http://groups.google.com/group/rubyonrails-talk?hl=en. > > > > > -- > > > > 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@googlegroups.com > > . > > > > To unsubscribe from this group, send email to > > > > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org<rubyonrails-talk%2Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> > > <rubyonrails-talk%2Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org<rubyonrails-talk%252Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> > > > > > . > > > > For more options, visit this group at > > > >http://groups.google.com/group/rubyonrails-talk?hl=en. > > > -- > > 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > > To unsubscribe from this group, send email to > > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org<rubyonrails-talk%2Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> > > . > > For more options, visit this group at > >http://groups.google.com/group/rubyonrails-talk?hl=en.-- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
no, with what i showed you you can do <%@user.comments.each |comment|%> <%=h comment.content%> <%comment.products.each do |product|%> <%=product.name%> <%end%> <%end%> also <%@product.comments.each |comment|%> <%=h comment.content%> <%comment.users.each do |user|%> <%=user.name%>%> <%end%> but what do you mean by and upload table??? On Fri, Sep 10, 2010 at 8:39 AM, Christian Fazzini < christian.fazzini-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Hi Radhames. Yea, the case you mention above would work. Except, since > you are suggesting I have a comment table on its own. Then I would > need to have a like and upload table on its own as well. > > If I needed to list recent interactions (to list down a user feed), I > would have to union join the comment, like and upload tables. If I had > one table called interactions, I could just query this ONE table and > add a where clause (user_id =12, for example) and sort by created_at. > Performance wise, it is better then having to union join 3 other > tables together... > > The question is now, whether this should be done using a polymorphic > association or STI > > On Sep 10, 8:16 am, radhames brito <rbri...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > dont touch the type fields. > > > > If you have a child model that you have to attach to different models use > > polymorphic associations. > > if you have 2 models with a few different fields use STI. > > > > if it guess too clomplex is means you choose wrong and you were so > suppose > > to use the other kind of association. > > > > thi the case you are saying you dont need any of those, only a comment > model > > that belongs to product and to user like this > > > > class user > > has_many comments ## the table should not > have > > a comment_id field > > has_many products :through =>comments > > > > class product > > has_many comments ## the table should not > have > > a comment_id field > > has_many users :through =>comments > > > > class comment > > belongs_to :user > > belongs_to :product > > > > the coment migration should be like this > > > > create_table :comments do |t| > > t.integer :user_id > > t.integer :product_id > > t.content > > t.timestamp > > > > On Thu, Sep 9, 2010 at 6:09 PM, Christian Fazzini < > > > > christian.fazz...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > Redhames, got it thanks! Have tested this and now seems to work. Even > > > the type field is put in automatically when the form submits. > > > > > Is this normal that the type field saves as "CitySuggestion" and > > > "BusinessSuggestion" respectively? Can I change the way it saves, as > > > "city" or "business", instead? > > > > > Can we talk about the design factor for this. I realise the potential > > > of STI''s now. However, lets assume this scenario. > > > > > Ive got user and product. A user can leave comments, like, upload > > > products. These are called interactions. On a product page, I need to > > > display the product and all comments for the product. I also have a > > > user page with a section that displays all the users recent > > > interactions, sorted by the created_at date. > > > > > I was thinking of using an STI for this, with something like: > > > > > class Interaction < ActiveRecord::Base > > > attr_accessible :user_id, :product_id, :comment, :ip_address, :type > > > > > ---------- > > > class Comment < Suggestion > > > attr_accessible :user_id, :product_id, :comment > > > > > ---------- > > > class Upload < Suggestion > > > attr_accessible :user_id, :product_id, :ip_address > > > > > ---------- > > > class Like < Suggestion > > > attr_accessible :user_id, :product_id > > > > > However, I was also considering using a polymorphic behavior. Or in > > > your opinion, would an STI be more suitable for this? > > > > > On Sep 10, 3:06 am, radhames brito <rbri...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > yes thats rigth, everything will behave as if you had 2 tables , is > > > normal > > > > RoR from now on. > > > > > > yes dont be afraid to ask. > > > > > > On Thu, Sep 9, 2010 at 1:06 PM, Christian Fazzini < > > > > > > christian.fazz...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > Thanks Radhames. Ok I got it up to there. I am assuming since we > are > > > > > creating controllers for city_suggestions and business_suggestions, > we > > > > > will also need to create view for them respectively? i.e. > /app/views/ > > > > > city_suggestions and /app/views/business_suggestions right? > > > > > > > I appreciate your patience and thorough explanation regarding STI. > > > > > Once I grasp this concept properly, I can apply the same knowledge > on > > > > > other cases :-) > > > > > > > On Sep 9, 10:26 pm, radhames brito <rbri...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > > sorry i forgot you use scaffold , here is the thing ill make a > guide > > > for > > > > > > this , from the migration step by step to the view > > > > > > > > create a table like this > > > > > > > > create_table :sugestions do |t| > > > > > > t.string first_name > > > > > > t.string last_name > > > > > > t.string email > > > > > > t.string business_name > > > > > > t.string business_address > > > > > > t.string city_name > > > > > > t.string type > > > > > > end > > > > > > > > no more tables are needed > > > > > > > > create a model > > > > > > > > Sugestion , (singular) as normal it should inherit from active > record > > > > > base > > > > > > like this > > > > > > > > class Sugestion < ActiveRecord::Base > > > > > > > > attr_accessible : first_name,last_name, email, business_name, > > > > > > business_address, city_name > > > > > > > > then create the tu other model that inherit from Sugestion, note > that > > > is > > > > > > they is a capital letter in the model name rails will put an > > > underscore > > > > > like > > > > > > this city_sugestions_controller > > > > > > > > class CitySugestion < ActiveRecord::Base > > > > > > > > attr_accessible : first_name,last_name, email, city_name > > > > > > > > and another > > > > > > > > class bussinessSugestion < ActiveRecord::Base > > > > > > > > attr_accessible : first_name,last_name, email,business_name, > > > > > > business_address > > > > > > > > note i think type should not be available with mass assignment. > > > > > > > > then create the controllers for the 2 sugestions classes > > > > > > > > city_sugestions_controller > > > > > > > > and > > > > > > > > bussiness_sugestions_controller > > > > > > > > from here one this controller will never notice you have only one > > > table > > > > > they > > > > > > will behave as if you had 2 different tables in the db > > > > > > > > in you views just refer to @bussinesssugestions and it will be > scoped > > > > > thanks > > > > > > to the type field that active record will automaticly use then > you > > > save > > > > > an > > > > > > object of either class. Dont try to access the type field using > > > > > > @citysuggestion.type or @suggestion.type as type is a ruby method > and > > > > > will > > > > > > be called instead of > > > > > > the table field, use @sugestion[:type] , the other fields can be > > > called > > > > > as > > > > > > normal. > > > > > > > > If you want to handle the sugestion class directly you can create > a > > > > > > sugestions_controller, it its corresponding viwes for it and have > a > > > named > > > > > > scope that filter each type. > > > > > > > > Dont be afraid to keep asking if you are still confuse and keep > in > > > mind > > > > > that > > > > > > in most case, people are not specting that you would use > scaffolds > > > every > > > > > > time since scaffold are more like a learning tool that an actual > way > > > of > > > > > > doing things. > > > > > > > > if you want to use scaffold anyway you can create the scaffold > and > > > skip > > > > > > creating the migrations with > > > > > > > > script/generate scaffold --skip-migrations > > > > > > > > On Thu, Sep 9, 2010 at 9:52 AM, Christian Fazzini < > > > > > > > > christian.fazz...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > > > Yes I know, I am just trying to understand how to implement > this > > > > > > > properly. It''s easy enough to rollback the migration and remove > the > > > > > > > respective migration files. However, I need to know whether I > need > > > > > > > controllers, models and views for citysuggestion and > > > > > > > businesssuggestion > > > > > > > > > On Sep 9, 9:46 pm, Marnen Laibow-Koser <li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> > > > wrote: > > > > > > > > Christian Fazzini wrote: > > > > > > > > > I thought you said I needed to scaffold the citysuggestion > and > > > > > > > > > businesssuggestion? Scaffold generates controllers, views, > and > > > > > models > > > > > > > > > (if they already dont exist)? > > > > > > > > > > > If I do rake db:migrate, it generates the tables in the db. > > > Should > > > > > I > > > > > > > > > remove the migration files that the scaffold generator > > > generates > > > > > > > > > before doing rake db:migrate? > > > > > > > > > > Stop relying so much on the scaffold generator. You''ve > probably > > > gone > > > > > > > > beyond the point where it''s useful. > > > > > > > > > > Best, > > > > > > > > -- > > > > > > > > Marnen Laibow-Koserhttp://www.marnen.org > > > > > > > > mar...-sbuyVjPbboAdnm+yROfE0A@public.gmane.org > > > > > > > > -- > > > > > > > > Posted viahttp://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<rubyonrails-talk%2Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> > <rubyonrails-talk%2Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org<rubyonrails-talk%252Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> > > > > > <rubyonrails-talk%2Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org<rubyonrails-talk%252Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> > <rubyonrails-talk%252Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org<rubyonrails-talk%25252Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> > > > > > > > > > <rubyonrails-talk%2Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org<rubyonrails-talk%252Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> > <rubyonrails-talk%252Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org<rubyonrails-talk%25252Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> > > > > > <rubyonrails-talk%252Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org<rubyonrails-talk%25252Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> > <rubyonrails-talk%25252Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org<rubyonrails-talk%2525252Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> > > > > > > > > > > > . > > > > > > > For more options, visit this group at > > > > > > >http://groups.google.com/group/rubyonrails-talk?hl=en. > > > > > > > -- > > > > > 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<rubyonrails-talk%2Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> > <rubyonrails-talk%2Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org<rubyonrails-talk%252Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> > > > > > <rubyonrails-talk%2Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org<rubyonrails-talk%252Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> > <rubyonrails-talk%252Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org<rubyonrails-talk%25252Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> > > > > > > > > > . > > > > > For more options, visit this group at > > > > >http://groups.google.com/group/rubyonrails-talk?hl=en. > > > > > -- > > > 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<rubyonrails-talk%2Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> > <rubyonrails-talk%2Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org<rubyonrails-talk%252Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> > > > > > . > > > For more options, visit this group at > > >http://groups.google.com/group/rubyonrails-talk?hl=en. > > -- > 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org<rubyonrails-talk%2Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> > . > For more options, visit this group at > http://groups.google.com/group/rubyonrails-talk?hl=en. > >-- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Basically when a user uploads content. Or when a user "likes" a product or comments on one. These three are interactions. If you are familiar with Facebook. The homepage displays a sort of user feed. This is what I am trying to achieve. To have something like this, I must have a single table. I was thinking of calling it "interaction". And then upload, like, and comment all inherit from this table. Sounds good? On Sep 10, 8:58 pm, radhames brito <rbri...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> no, with what i showed you you can do > > <%...@user.comments.each |comment|%> > <%=h comment.content%> > <%comment.products.each do |product|%> > <%=product.name%> > <%end%> > <%end%> > > also > > <%...@product.comments.each |comment|%> > <%=h comment.content%> > <%comment.users.each do |user|%> > <%=user.name%>%> > <%end%> > > but what do you mean by and upload table??? > > On Fri, Sep 10, 2010 at 8:39 AM, Christian Fazzini < > > christian.fazz...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > Hi Radhames. Yea, the case you mention above would work. Except, since > > you are suggesting I have a comment table on its own. Then I would > > need to have a like and upload table on its own as well. > > > If I needed to list recent interactions (to list down a user feed), I > > would have to union join the comment, like and upload tables. If I had > > one table called interactions, I could just query this ONE table and > > add a where clause (user_id =12, for example) and sort by created_at. > > Performance wise, it is better then having to union join 3 other > > tables together... > > > The question is now, whether this should be done using a polymorphic > > association or STI > > > On Sep 10, 8:16 am, radhames brito <rbri...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > dont touch the type fields. > > > > If you have a child model that you have to attach to different models use > > > polymorphic associations. > > > if you have 2 models with a few different fields use STI. > > > > if it guess too clomplex is means you choose wrong and you were so > > suppose > > > to use the other kind of association. > > > > thi the case you are saying you dont need any of those, only a comment > > model > > > that belongs to product and to user like this > > > > class user > > > has_many comments ## the table should not > > have > > > a comment_id field > > > has_many products :through =>comments > > > > class product > > > has_many comments ## the table should not > > have > > > a comment_id field > > > has_many users :through =>comments > > > > class comment > > > belongs_to :user > > > belongs_to :product > > > > the coment migration should be like this > > > > create_table :comments do |t| > > > t.integer :user_id > > > t.integer :product_id > > > t.content > > > t.timestamp > > > > On Thu, Sep 9, 2010 at 6:09 PM, Christian Fazzini < > > > > christian.fazz...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > Redhames, got it thanks! Have tested this and now seems to work. Even > > > > the type field is put in automatically when the form submits. > > > > > Is this normal that the type field saves as "CitySuggestion" and > > > > "BusinessSuggestion" respectively? Can I change the way it saves, as > > > > "city" or "business", instead? > > > > > Can we talk about the design factor for this. I realise the potential > > > > of STI''s now. However, lets assume this scenario. > > > > > Ive got user and product. A user can leave comments, like, upload > > > > products. These are called interactions. On a product page, I need to > > > > display the product and all comments for the product. I also have a > > > > user page with a section that displays all the users recent > > > > interactions, sorted by the created_at date. > > > > > I was thinking of using an STI for this, with something like: > > > > > class Interaction < ActiveRecord::Base > > > > attr_accessible :user_id, :product_id, :comment, :ip_address, :type > > > > > ---------- > > > > class Comment < Suggestion > > > > attr_accessible :user_id, :product_id, :comment > > > > > ---------- > > > > class Upload < Suggestion > > > > attr_accessible :user_id, :product_id, :ip_address > > > > > ---------- > > > > class Like < Suggestion > > > > attr_accessible :user_id, :product_id > > > > > However, I was also considering using a polymorphic behavior. Or in > > > > your opinion, would an STI be more suitable for this? > > > > > On Sep 10, 3:06 am, radhames brito <rbri...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > yes thats rigth, everything will behave as if you had 2 tables , is > > > > normal > > > > > RoR from now on. > > > > > > yes dont be afraid to ask. > > > > > > On Thu, Sep 9, 2010 at 1:06 PM, Christian Fazzini < > > > > > > christian.fazz...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > > Thanks Radhames. Ok I got it up to there. I am assuming since we > > are > > > > > > creating controllers for city_suggestions and business_suggestions, > > we > > > > > > will also need to create view for them respectively? i.e. > > /app/views/ > > > > > > city_suggestions and /app/views/business_suggestions right? > > > > > > > I appreciate your patience and thorough explanation regarding STI. > > > > > > Once I grasp this concept properly, I can apply the same knowledge > > on > > > > > > other cases :-) > > > > > > > On Sep 9, 10:26 pm, radhames brito <rbri...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > > > sorry i forgot you use scaffold , here is the thing ill make a > > guide > > > > for > > > > > > > this , from the migration step by step to the view > > > > > > > > create a table like this > > > > > > > > create_table :sugestions do |t| > > > > > > > t.string first_name > > > > > > > t.string last_name > > > > > > > t.string email > > > > > > > t.string business_name > > > > > > > t.string business_address > > > > > > > t.string city_name > > > > > > > t.string type > > > > > > > end > > > > > > > > no more tables are needed > > > > > > > > create a model > > > > > > > > Sugestion , (singular) as normal it should inherit from active > > record > > > > > > base > > > > > > > like this > > > > > > > > class Sugestion < ActiveRecord::Base > > > > > > > > attr_accessible : first_name,last_name, email, business_name, > > > > > > > business_address, city_name > > > > > > > > then create the tu other model that inherit from Sugestion, note > > that > > > > is > > > > > > > they is a capital letter in the model name rails will put an > > > > underscore > > > > > > like > > > > > > > this city_sugestions_controller > > > > > > > > class CitySugestion < ActiveRecord::Base > > > > > > > > attr_accessible : first_name,last_name, email, city_name > > > > > > > > and another > > > > > > > > class bussinessSugestion < ActiveRecord::Base > > > > > > > > attr_accessible : first_name,last_name, email,business_name, > > > > > > > business_address > > > > > > > > note i think type should not be available with mass assignment. > > > > > > > > then create the controllers for the 2 sugestions classes > > > > > > > > city_sugestions_controller > > > > > > > > and > > > > > > > > bussiness_sugestions_controller > > > > > > > > from here one this controller will never notice you have only one > > > > table > > > > > > they > > > > > > > will behave as if you had 2 different tables in the db > > > > > > > > in you views just refer to @bussinesssugestions and it will be > > scoped > > > > > > thanks > > > > > > > to the type field that active record will automaticly use then > > you > > > > save > > > > > > an > > > > > > > object of either class. Dont try to access the type field using > > > > > > > @citysuggestion.type or @suggestion.type as type is a ruby method > > and > > > > > > will > > > > > > > be called instead of > > > > > > > the table field, use @sugestion[:type] , the other fields can be > > > > called > > > > > > as > > > > > > > normal. > > > > > > > > If you want to handle the sugestion class directly you can create > > a > > > > > > > sugestions_controller, it its corresponding viwes for it and have > > a > > > > named > > > > > > > scope that filter each type. > > > > > > > > Dont be afraid to keep asking if you are still confuse and keep > > in > > > > mind > > > > > > that > > > > > > > in most case, people are not specting that you would use > > scaffolds > > > > every > > > > > > > time since scaffold are more like a learning tool that an actual > > way > > > > of > > > > > > > doing things. > > > > > > > > if you want to use scaffold anyway you can create the scaffold > > and > > > > skip > > > > > > > creating the migrations with > > > > > > > > script/generate scaffold --skip-migrations > > > > > > > > On Thu, Sep 9, 2010 at 9:52 AM, Christian Fazzini < > > > > > > > > christian.fazz...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > > > > Yes I know, I am just trying to understand how to implement > > this > > > > > > > > properly. It''s easy enough to rollback the migration and remove > > the > > > > > > > > respective migration files. However, I need to know whether I > > need > > > > > > > > controllers, models and views for citysuggestion and > > > > > > > > businesssuggestion > > > > > > > > > On Sep 9, 9:46 pm, Marnen Laibow-Koser <li...-fsXkhYbjdPsM1dTnIXmMWg@public.gmane.orgm> > > > > wrote: > > > > > > > > > Christian Fazzini wrote: > > > > > > > > > > I thought you said I needed to scaffold the citysuggestion > > and > > > > > > > > > > businesssuggestion? Scaffold generates controllers, views, > > and > > > > > > models > > > > > > > > > > (if they already dont exist)? > > > > > > > > > > > If I do rake db:migrate, it generates the tables in the db. > > > > Should > > > > > > I > > > > > > > > > > remove the migration files that the scaffold generator > > > > generates > > > > > > > > > > before doing rake db:migrate? > > > > > > > > > > Stop relying so much on the scaffold generator. You''ve > > probably > > > > gone > > > > > > > > > beyond the point where it''s useful. > > > > > > > > > > Best, > > > > > > > > > -- > > > > > > > > > Marnen Laibow-Koserhttp://www.marnen.org > > > > > > > > > mar...-sbuyVjPbboAdnm+yROfE0A@public.gmane.org > > > > > > > > > -- > > > > > > > > > Posted viahttp://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<rubyonrails-talk%2Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> > > <rubyonrails-talk%2Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org<rubyonrails-talk%252Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> > > > > > <rubyonrails-talk%2Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org<rubyonrails-talk%252Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> > > ... > > read more »-- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
i think i dont understand very well because i think that what you are saying can be achieve with the code in the previous mail. this is how i show a user all his comments <%@user.comments.each |comment|%> <%=h comment.content%> <%end%> and this is how i show a user all the products he has commented on <%@user.comments.each |comment|%> <%comment.products.each do |product|%> <%=product.name%> <%end%> <%end%> would add a like table since liking can only happen once but comments can happen a lot so they are not the same. this new like table you have the same association as the comments table. the like table con not be treated as the comment table since a user can comment a lot on one product , but can only like or dislike once. On Fri, Sep 10, 2010 at 10:33 PM, Christian Fazzini < christian.fazzini-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Basically when a user uploads content. Or when a user "likes" a > product or comments on one. These three are interactions. If you are > familiar with Facebook. The homepage displays a sort of user feed. > This is what I am trying to achieve. To have something like this, I > must have a single table. I was thinking of calling it "interaction". > And then upload, like, and comment all inherit from this table. Sounds > good? > > On Sep 10, 8:58 pm, radhames brito <rbri...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > no, with what i showed you you can do > > > > <%...@user.comments.each |comment|%> > > <%=h comment.content%> > > <%comment.products.each do |product|%> > > <%=product.name%> > > <%end%> > > <%end%> > > > > also > > > > <%...@product.comments.each |comment|%> > > <%=h comment.content%> > > <%comment.users.each do |user|%> > > <%=user.name%>%> > > <%end%> > > > > but what do you mean by and upload table??? > > > > On Fri, Sep 10, 2010 at 8:39 AM, Christian Fazzini < > > > > christian.fazz...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > Hi Radhames. Yea, the case you mention above would work. Except, since > > > you are suggesting I have a comment table on its own. Then I would > > > need to have a like and upload table on its own as well. > > > > > If I needed to list recent interactions (to list down a user feed), I > > > would have to union join the comment, like and upload tables. If I had > > > one table called interactions, I could just query this ONE table and > > > add a where clause (user_id =12, for example) and sort by created_at. > > > Performance wise, it is better then having to union join 3 other > > > tables together... > > > > > The question is now, whether this should be done using a polymorphic > > > association or STI > > > > > On Sep 10, 8:16 am, radhames brito <rbri...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > dont touch the type fields. > > > > > > If you have a child model that you have to attach to different models > use > > > > polymorphic associations. > > > > if you have 2 models with a few different fields use STI. > > > > > > if it guess too clomplex is means you choose wrong and you were so > > > suppose > > > > to use the other kind of association. > > > > > > thi the case you are saying you dont need any of those, only a > comment > > > model > > > > that belongs to product and to user like this > > > > > > class user > > > > has_many comments ## the table should > not > > > have > > > > a comment_id field > > > > has_many products :through =>comments > > > > > > class product > > > > has_many comments ## the table should > not > > > have > > > > a comment_id field > > > > has_many users :through =>comments > > > > > > class comment > > > > belongs_to :user > > > > belongs_to :product > > > > > > the coment migration should be like this > > > > > > create_table :comments do |t| > > > > t.integer :user_id > > > > t.integer :product_id > > > > t.content > > > > t.timestamp > > > > > > On Thu, Sep 9, 2010 at 6:09 PM, Christian Fazzini < > > > > > > christian.fazz...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > Redhames, got it thanks! Have tested this and now seems to work. > Even > > > > > the type field is put in automatically when the form submits. > > > > > > > Is this normal that the type field saves as "CitySuggestion" and > > > > > "BusinessSuggestion" respectively? Can I change the way it saves, > as > > > > > "city" or "business", instead? > > > > > > > Can we talk about the design factor for this. I realise the > potential > > > > > of STI''s now. However, lets assume this scenario. > > > > > > > Ive got user and product. A user can leave comments, like, upload > > > > > products. These are called interactions. On a product page, I need > to > > > > > display the product and all comments for the product. I also have a > > > > > user page with a section that displays all the users recent > > > > > interactions, sorted by the created_at date. > > > > > > > I was thinking of using an STI for this, with something like: > > > > > > > class Interaction < ActiveRecord::Base > > > > > attr_accessible :user_id, :product_id, :comment, :ip_address, :type > > > > > > > ---------- > > > > > class Comment < Suggestion > > > > > attr_accessible :user_id, :product_id, :comment > > > > > > > ---------- > > > > > class Upload < Suggestion > > > > > attr_accessible :user_id, :product_id, :ip_address > > > > > > > ---------- > > > > > class Like < Suggestion > > > > > attr_accessible :user_id, :product_id > > > > > > > However, I was also considering using a polymorphic behavior. Or in > > > > > your opinion, would an STI be more suitable for this? > > > > > > > On Sep 10, 3:06 am, radhames brito <rbri...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > > yes thats rigth, everything will behave as if you had 2 tables , > is > > > > > normal > > > > > > RoR from now on. > > > > > > > > yes dont be afraid to ask. > > > > > > > > On Thu, Sep 9, 2010 at 1:06 PM, Christian Fazzini < > > > > > > > > christian.fazz...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > > > Thanks Radhames. Ok I got it up to there. I am assuming since > we > > > are > > > > > > > creating controllers for city_suggestions and > business_suggestions, > > > we > > > > > > > will also need to create view for them respectively? i.e. > > > /app/views/ > > > > > > > city_suggestions and /app/views/business_suggestions right? > > > > > > > > > I appreciate your patience and thorough explanation regarding > STI. > > > > > > > Once I grasp this concept properly, I can apply the same > knowledge > > > on > > > > > > > other cases :-) > > > > > > > > > On Sep 9, 10:26 pm, radhames brito <rbri...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > > > > sorry i forgot you use scaffold , here is the thing ill make > a > > > guide > > > > > for > > > > > > > > this , from the migration step by step to the view > > > > > > > > > > create a table like this > > > > > > > > > > create_table :sugestions do |t| > > > > > > > > t.string first_name > > > > > > > > t.string last_name > > > > > > > > t.string email > > > > > > > > t.string business_name > > > > > > > > t.string business_address > > > > > > > > t.string city_name > > > > > > > > t.string type > > > > > > > > end > > > > > > > > > > no more tables are needed > > > > > > > > > > create a model > > > > > > > > > > Sugestion , (singular) as normal it should inherit from > active > > > record > > > > > > > base > > > > > > > > like this > > > > > > > > > > class Sugestion < ActiveRecord::Base > > > > > > > > > > attr_accessible : first_name,last_name, email, business_name, > > > > > > > > business_address, city_name > > > > > > > > > > then create the tu other model that inherit from Sugestion, > note > > > that > > > > > is > > > > > > > > they is a capital letter in the model name rails will put an > > > > > underscore > > > > > > > like > > > > > > > > this city_sugestions_controller > > > > > > > > > > class CitySugestion < ActiveRecord::Base > > > > > > > > > > attr_accessible : first_name,last_name, email, city_name > > > > > > > > > > and another > > > > > > > > > > class bussinessSugestion < ActiveRecord::Base > > > > > > > > > > attr_accessible : first_name,last_name, email,business_name, > > > > > > > > business_address > > > > > > > > > > note i think type should not be available with mass > assignment. > > > > > > > > > > then create the controllers for the 2 sugestions classes > > > > > > > > > > city_sugestions_controller > > > > > > > > > > and > > > > > > > > > > bussiness_sugestions_controller > > > > > > > > > > from here one this controller will never notice you have only > one > > > > > table > > > > > > > they > > > > > > > > will behave as if you had 2 different tables in the db > > > > > > > > > > in you views just refer to @bussinesssugestions and it will > be > > > scoped > > > > > > > thanks > > > > > > > > to the type field that active record will automaticly use > then > > > you > > > > > save > > > > > > > an > > > > > > > > object of either class. Dont try to access the type field > using > > > > > > > > @citysuggestion.type or @suggestion.type as type is a ruby > method > > > and > > > > > > > will > > > > > > > > be called instead of > > > > > > > > the table field, use @sugestion[:type] , the other fields can > be > > > > > called > > > > > > > as > > > > > > > > normal. > > > > > > > > > > If you want to handle the sugestion class directly you can > create > > > a > > > > > > > > sugestions_controller, it its corresponding viwes for it and > have > > > a > > > > > named > > > > > > > > scope that filter each type. > > > > > > > > > > Dont be afraid to keep asking if you are still confuse and > keep > > > in > > > > > mind > > > > > > > that > > > > > > > > in most case, people are not specting that you would use > > > scaffolds > > > > > every > > > > > > > > time since scaffold are more like a learning tool that an > actual > > > way > > > > > of > > > > > > > > doing things. > > > > > > > > > > if you want to use scaffold anyway you can create the > scaffold > > > and > > > > > skip > > > > > > > > creating the migrations with > > > > > > > > > > script/generate scaffold --skip-migrations > > > > > > > > > > On Thu, Sep 9, 2010 at 9:52 AM, Christian Fazzini < > > > > > > > > > > christian.fazz...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > > > > > Yes I know, I am just trying to understand how to implement > > > this > > > > > > > > > properly. It''s easy enough to rollback the migration and > remove > > > the > > > > > > > > > respective migration files. However, I need to know whether > I > > > need > > > > > > > > > controllers, models and views for citysuggestion and > > > > > > > > > businesssuggestion > > > > > > > > > > > On Sep 9, 9:46 pm, Marnen Laibow-Koser < > li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> > > > > > wrote: > > > > > > > > > > Christian Fazzini wrote: > > > > > > > > > > > I thought you said I needed to scaffold the > citysuggestion > > > and > > > > > > > > > > > businesssuggestion? Scaffold generates controllers, > views, > > > and > > > > > > > models > > > > > > > > > > > (if they already dont exist)? > > > > > > > > > > > > > If I do rake db:migrate, it generates the tables in the > db. > > > > > Should > > > > > > > I > > > > > > > > > > > remove the migration files that the scaffold generator > > > > > generates > > > > > > > > > > > before doing rake db:migrate? > > > > > > > > > > > > Stop relying so much on the scaffold generator. You''ve > > > probably > > > > > gone > > > > > > > > > > beyond the point where it''s useful. > > > > > > > > > > > > Best, > > > > > > > > > > -- > > > > > > > > > > Marnen Laibow-Koserhttp://www.marnen.org > > > > > > > > > > mar...-sbuyVjPbboAdnm+yROfE0A@public.gmane.org > > > > > > > > > > -- > > > > > > > > > > Posted viahttp://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<rubyonrails-talk%2Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> > <rubyonrails-talk%2Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org<rubyonrails-talk%252Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> > > > > > <rubyonrails-talk%2Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org<rubyonrails-talk%252Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> > <rubyonrails-talk%252Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org<rubyonrails-talk%25252Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> > > > > > > > > > <rubyonrails-talk%2Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org<rubyonrails-talk%252Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> > <rubyonrails-talk%252Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org<rubyonrails-talk%25252Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> > > > > > > ... > > > > read more » > > -- > 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org<rubyonrails-talk%2Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> > . > For more options, visit this group at > http://groups.google.com/group/rubyonrails-talk?hl=en. > >-- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.