0
기본 포럼을 구성했습니다. 게시물 # index 조치가 parent_post_id가 nil이 아닌 레코드 만 표시하도록하고 응답 게시물이 아닌 레코드를 표시하도록합니다. 나는 삐걱 소리를 내었습니다. 그러나 제대로 설정했는지 확신 할 수 없습니다.ActiveRecord, 부모 개체가없는 개체 만
#app/controllers/posts_controller.rb
def index
@forum = Forum.find(params[:forum_id])
@posts = @forum.posts.where{ |post| post.thread == nil }
end
#app/models/post.rb
class Post < ActiveRecord::Base
has_many :replies, :class_name => "Post"
belongs_to :thread, :class_name => "Post", :foreign_key => "parent_post_id"
end
#config/initializers/squeel.rb
Squeel.configure do |config|
# To load hash extensions (to allow for AND (&), OR (|), and NOT (-) against
# hashes of conditions)
config.load_core_extensions :hash
# To load symbol extensions (for a subset of the old MetaWhere functionality,
# via ARel predicate methods on Symbols: :name.matches, etc)
config.load_core_extensions :symbol
# To load both hash and symbol extensions
config.load_core_extensions :hash, :symbol
end
불행히도 이것은 작동하지 않는 것 같습니다. 'Post Load '(0.1ms) SELECT "posts". * FROM "posts"where "posts". "forum_id"= 1'은 여전히 콘솔에서 처리되고 있으며 모든 게시물이 통과됩니다. 레벨 것들. – DVG
레일즈 콘솔 자체에 문장을 입력 해보십시오. 어떻게 든 where 절을 추가하지 않았습니다. –
그래, 내가보기 레이어에서 망쳐 놨어 – DVG