以下のようなテーブルがあります
articlesテーブル
- name - url - blog_id
blogsテーブル
- name - url
http://localhost:3000/blogs/1にアクセスした時にそのブログに紐づく記事一覧を表示したいのですがどうすればいいでしょうか?
blogモデル
lang
1class Article < ActiveRecord::Base 2 belongs_to :blog 3end
articleモデル
lang
1class Blog < ActiveRecord::Base 2 has_many :articles 3end 4
BlogsController
lang
1class BlogsController < ApplicationController 2 before_action :set_blog, only: [:show, :edit, :update, :destroy] 3 4 # GET /blogs 5 # GET /blogs.json 6 def index 7 @blogs = Blog.all 8 end 9 10 # GET /blogs/1 11 # GET /blogs/1.json 12 def show 13 end 14 15以下略
回答1件
あなたの回答
tips
プレビュー
2015/02/16 01:38