Thanks Philip. After reading your response, I tried doing another dummy
application myself, and in the middle of getting everything set up, I
realized that I didn’t restart the script/server after adding the
include. So I went back to my other application, and this worked.
Occam’s razor :-).
Sorry to hound you with additional questions, but I was wondering if you
had time for one more.
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)
Thank you!
Phillip Ridlen wrote:
I’m unable to duplicate your problem with Rails 2.3.5.
I just learned that config.gem "amatch"
automatically requires the
library
with the same name, so you shouldn’t need to put require "amatch"
anywhere
in the application. Same goes for Rails 3 and Bundler.
I just whipped up a simple scaffold application, here’s what it looks
like
(Maybe this will help(?)–I’m not very familiar with how Amatch works,
maybe
I’ll look into that):
config/environment.rb
config.gem “amatch”
app/models/post.rb
class Post < ActiveRecord::Base
include Amatch
end
app/controllers/posts_controller.rb
class PostsController < ApplicationController
def index
@posts = Post.all
m = Post::Sellers.new("hello")
respond_to do |format|
format.html # index.html.erb
format.xml { render :xml => @posts }
end
end
end
This doesn’t throw any errors for me.
Phillip Ridlen
@philtr