routes.rb
root :to => 'articles#index'
マイクロポスト モデル:
class Micropost < ActiveRecord::Base
attr_accessible :content, :user_id
belongs_to :user
validates :user_id, presence: true
validates :content, presence: true, length: { maximum: 100 }
end
記事のモデル:
class Article < ActiveRecord::Base
attr_accessible :content, :title
validates :title, :presence => true,
:length => { :minimum => 2 }
belongs_to :user
end
そして、articles_controller.rb のインデックス define_method
def index
@articles = Article.paginate(:page => params[:page],
:per_page => 5,
:order => 'created_at DESC')
respond_to do |format|
format.html
format.json { render json: @articles }
end
end
article_controller#index と index ビューの書き方はわかりませんが。