This project is archived and is in readonly mode.
Add magic encoding comment to generated files
-
Glenn Powell
I think your problem here is that you aren't creating your model correctly. The scaffold (not skaffold ??) generator does not add anything extra to your models/comment.rb file. So you need to explicitly add the reference to post:
class Comment < ActiveRecord::Base belongs_to :post end
This should allow the fixtures to work as they are generated.
-
Glenn Powell
woops...
class Comment < ActiveRecord::Base belongs_to :post end -
Adrian Mugnolo
Agree with Glenn. The generated fixtures are actually giving you a hint about the "foxy fixtures" feature. This allows using record label references instead of numeric ids on fixtures.
For example,
post_by_john: author: John Smith title: How to implement "lorem ipsum" body: > Lorem ipsum dolor sit amet, consectetur adipisicing elit.comment_on_johns_post_by_mary: author: Mary White body: > That was a great post about using "lorem ipsum", John. post: post_by_john comment_on_johns_post_by_peter: author: Peter Black body: > Not sure, take a look at "dolor sit amet" instead. post: post_by_johnSo, IMO the generated files are correct. You should be using more "post" and less "post_id" on fixtures.
-
Tarmo Tänav
Indeed the expectation is that foxy fixtures be used, but perhaps the real fix here is automatically generating a model with a belongs_to for the "references" attributes?
-
Adrian Mugnolo
+1 for Tarmo's idea. Still, I would stop there and don't try to check if the referenced model includes the matching has_many/has_one.
-
Repository
- State changed from new to resolved
(from [9223a919111867e6b47b2627c30d8eb21e8ac7d9]) Generate belongs_to associations automatically for 'references' types [#640 Add magic encoding comment to generated files state:resolved] http://github.com/rails/rails/co...
-
Jeff Kreeftmeijer
Automatic cleanup of spam.
-
Ryan Bigg
Automatic cleanup of spam.
-
Jeff Kreeftmeijer
Automatic cleanup of spam.
-
Jeff Kreeftmeijer
Automatic cleanup of spam.