0
基本的なフォーラムをセットアップしました。私は、posts_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