0

Railsについて非常に大きな質問があります。ブログに関する Web サイトを作成する必要があり、ユーザー登録を許可し、ユーザーが記事とコメントの追加、削除、編集、および選択を可能にする独自の管理インターフェイスを持っているとします。との操作は、将来、他の位置で使用される可能性がありますarticlecomment

したがって、articleモデルとcommentモデルがあります。

次に、ユーザー コントローラーを作成します。

class UserController < ApplicationController    
  def articleList   
  end

  def articleSave   
  end

  def articleUpdate 
  end

  def articleDestroy    
  end

  def articleEdit   
  end

  def articleAdd    
  end

  def commentList   
  end

  def commentDestroy    
  end

  def commentEdit   
  end
end

しかし、見栄えが悪く、ユーザー管理コントロールに多くの機能がある場合、このユーザー コントローラーは非常に大きくなります。リクエストを処理するためにarticleコントローラーとコントローラーを作成する必要がありますか? commentアーティクル コントローラーに分離するだけで、次のようになります。

class ArticleController < ApplicationController 
  def list      
  end

  def save  
  end

  def update    
  end

  def destroy   
  end

  def edit
  end

  def add   
  end
end

コメント コントローラは次のとおりです。

class CommentController < ApplicationController      
  def list  
  end

  def destroy
  end

  def edit  
  end

  def update
  end
end

構造を整理する方法がわかりません。

4

1 に答える 1

0

Users Articlesとのそれぞれに個別のコントローラを用意しますが、 insideとinsideでCommentsネストします。これは、あなたが説明した概念間の関係に合っているようですCommentsArticlesArticlesUsers

http://www.sentia.com.au/blog/when-to-use-nested-controllers-in-your-rails-apps および http://guides.rubyonrails.org/routing.html#nested-resourcesを参照 してください。 コントローラのネストの詳細については。

于 2013-09-27T07:25:13.833 に答える