Ruby on Rails
Wednesday, January 30, 2013
hi
thanks for answer sorry I quite new in RoR. If I do how u said, will I have to validate "manually" all the attributes for details ?
Le mercredi 30 janvier 2013 15:27:43 UTC+1, jim a écrit :
-- Le mercredi 30 janvier 2013 15:27:43 UTC+1, jim a écrit :
On Wed, Jan 30, 2013 at 6:48 PM, oto iashvili <optimum...@laposte.net> wrote:
I want to do@ad = Ad.attributes(params[:ad])
maybe Im wrong, but as I understood about polymorphic in rails, this would thow an error say that ad_real_estate_details does not existAs I've said, don't use accepts_nested_attributes_for. Create a getter and setter method for each kind of details that you want.If you don't want to do that, create an attr_accessor for the details, and create the detail record in a callback.
Le mardi 29 janvier 2013 13:39:18 UTC+1, jim a écrit :On Tue, Jan 29, 2013 at 7:41 PM, oto iashvili <optimum...@laposte.net> wrote:
Hi,thanks for answer. My pb with polymorphic is that I would have to create first in db a ligne for ad_real_estate_details and then create my ad, what is non sense for me, in terms of logic.and it might brings some pb as I read there http://stackoverflow.com/questions/3969025/accepts-nes ted-attributes-for-with-belong s-to-polymorphic lets have another example which is almost the sameimage we have Student (age, classe, ...) and Teacher (subject_taught) classes that inherit from User classes. I would be non sense to create first a Teacher entity, and then to link it to User, no ?Why are you thinking of creating the details first? Why not create the ad first, then add the details later? Sometimes, accepts_nested_attributes_for is not always the answer for creating association records. Try to look into virtual attributesand callbacks.To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-ta...@googlegroups--
Le lundi 28 janvier 2013 01:10:30 UTC+1, jim a écrit :On Mon, Jan 28, 2013 at 6:27 AM, oto iashvili <optimum...@laposte.net> wrote:
hi,i' trying to re-create my project from php to rails. But now Im faced with a pb to witch I had solution with php, but I cant figure how to make it work with railshere my tablesadsidcategory_idtitletextad_real_estate_detailsidad_idnb_roomfloorad_car_detailsidad_idcolorbrandhere what I succeed to do
class Ad < ActiveRecord::Baseattr_accessible :category_id :title, :text, :ad_real_estate_detailshas_one :ad_real_estate_detailsaccepts_nested_attributes_for :ad_real_estate_details, allow_destroy: trueendclass AdRealEstateDetail < ActiveRecord::Basebelongs_to :advalidates :ad_id, presence: trueendbut this only work for other category than real_estateso I was thinking of polymorphism, but polymorphism mean I should add a reference in my "ad" table to the detail tables, and remove annonce_id from detail tables , what I thing is non-sense as some ads can have no details, but details are non-sense without an ad.i think you have it right when you mentioned using polymorphic associations. it is fine to leave the polymorphic associationnil if the ad has no details if that's what you're worried about.I was also thinking of a class AdDetails, and AdRealEstateDetail would inherite from it, but this is not possible with rails as all subclasses will share the same tabledoes anyone have a solution for this kind of problem ?thanksTo post to this group, send email to rubyonra...@googlegroups.com.--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group, send email to rubyonrails-ta...@googlegroups.com .
To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/GLpFbbHm0 .ogJ
For more options, visit https://groups.google.com/groups/opt_out .
--
------------------------------------------------------------ -
visit my blog at http://jimlabs.heroku.comYou received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group..com .To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/zT4pri8N4 .GUJ --
------------------------------------------------------------ -
visit my blog at http://jimlabs.heroku.com--To view this discussion on the web visit https://groups.google.com/d/
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-ta...@googlegroups.com .
To post to this group, send email to rubyonra...@googlegroups.com .msg/rubyonrails-talk/-/ .DT2QhvrfLpUJ --
------------------------------------------------------------ -
visit my blog at http://jimlabs.heroku.com
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/fSjtYW_hRBEJ.
For more options, visit https://groups.google.com/groups/opt_out.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment