I''m having a hard time limiting the scope of new comments to the Post model. So, for validates_uniqueness_of :title in the comment.rb model, that uniqueness would only be attached to the post I''m commenting to, not globally among all comments in the application. I tried putting this in comment.rb: validates_uniqueness_of :title, :scope => :post but got this error message in my terminal: Processing CommentsController#create (for 127.0.0.1 at 2010-08-16 21:28:32) [POST] Parameters: {"comment"=>{"title"=>"rent"}, "commit"=>"Submit Your Comment", "authenticity_token"=>"z5AzsFgaJPdvGiTyy3Yeyb8f0RV+dmpdw5PanAadjOw=", "game_id"=>"5"} Post Load (0.2ms) SELECT * FROM "posts" WHERE ("posts"."id" = 5) CACHE (0.0ms) SELECT * FROM "posts" WHERE ("posts"."id" = 5) Response Load (0.0ms) SQLite3::SQLException: no such column: comments.posts: SELECT "comments".id FROM "comments" WHERE ("comments"."title" = ''rent'' AND "comments".post = 5) LIMIT 1 ActiveRecord::StatementInvalid (SQLite3::SQLException: no such column: comments.post: SELECT "comments".id FROM "comments" WHERE ("comments"."title" = ''rent'' AND "comments".post = 5) LIMIT 1): app/controllers/comments_controller.rb:4:in `create'' Rendered rescues/_trace (110.5ms) Rendered rescues/_request_and_response (1.2ms) Rendering rescues/layout (internal_server_error) -- 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.
On Aug 19, 2010, at 11:23 AM, Ze Ca wrote:> > I''m having a hard time limiting the scope of new comments to the Post > model. So, for validates_uniqueness_of :title in the comment.rb model, > that uniqueness would only be attached to the post I''m commenting to, > not globally among all comments in the application. > > I tried putting this in comment.rb: > > validates_uniqueness_of :title, :scope => :post:scope => :post_id> > but got this error message in my terminal: > > Processing CommentsController#create (for 127.0.0.1 at 2010-08-16 > 21:28:32) [POST] > Parameters: {"comment"=>{"title"=>"rent"}, "commit"=>"Submit Your > Comment", > "authenticity_token"=>"z5AzsFgaJPdvGiTyy3Yeyb8f0RV+dmpdw5PanAadjOw=", > "game_id"=>"5"} > Post Load (0.2ms) SELECT * FROM "posts" WHERE ("posts"."id" = 5) > CACHE (0.0ms) SELECT * FROM "posts" WHERE ("posts"."id" = 5) > Response Load (0.0ms) SQLite3::SQLException: no such column: > comments.posts: SELECT "comments".id FROM "comments" WHERE > ("comments"."title" = ''rent'' AND "comments".post = 5) LIMIT 1 > > ActiveRecord::StatementInvalid (SQLite3::SQLException: no such column: > comments.post: SELECT "comments".id FROM "comments" WHERE > ("comments"."title" = ''rent'' AND "comments".post = 5) LIMIT 1): > app/controllers/comments_controller.rb:4:in `create'' > > Rendered rescues/_trace (110.5ms) > Rendered rescues/_request_and_response (1.2ms) > Rendering rescues/layout (internal_server_error) > -- > 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org > . > For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en > . >Rob Biedenharn Rob-xa9cJyRlE0mWcWVYNo9pwxS2lgjeYSpx@public.gmane.org http://AgileConsultingLLC.com/ rab-/VpnD74mH8+00s0LW7PaslaTQe2KTcn/@public.gmane.org http://GaslightSoftware.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.
Ah, ok. That did it. I see now I would want to limit the scope to the post_id column, instead of the post table. Thank you! Rob Biedenharn wrote:> On Aug 19, 2010, at 11:23 AM, Ze Ca wrote: > >> >> I''m having a hard time limiting the scope of new comments to the Post >> model. So, for validates_uniqueness_of :title in the comment.rb model, >> that uniqueness would only be attached to the post I''m commenting to, >> not globally among all comments in the application. >> >> I tried putting this in comment.rb: >> >> validates_uniqueness_of :title, :scope => :post > > :scope => :post_id > >> CACHE (0.0ms) SELECT * FROM "posts" WHERE ("posts"."id" = 5) >> Rendered rescues/_request_and_response (1.2ms) >> . >> For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en >> . >> > > Rob Biedenharn > Rob-xa9cJyRlE0mWcWVYNo9pwxS2lgjeYSpx@public.gmane.org http://AgileConsultingLLC.com/ > rab-/VpnD74mH8+00s0LW7PaslaTQe2KTcn/@public.gmane.org http://GaslightSoftware.com/-- 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.