以下のようなテーブルがあります
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