いつもありがとうございます。
今回は飲食店のモデルを地域ごとに分けるRuby on Railsのカテゴリを設置したかったのですが、これに苦戦しています。
目標は
http://***.com/tokyo/restaurant/1
ページを作成することです。
下記のブログを見ながら作っているのですが、どうもうまくいっていません。
http://keitanxkeitan.hatenablog.com/entry/2014/05/29/003954
Ruby
1class CreateAreas < ActiveRecord::Migration[5.0] 2 def change 3 create_table :areas do |t| 4 t.string :name 5 6 t.timestamps 7 end 8 end 9end
※ 2017****_create_areas.rb
Ruby
1class AddAreaIdToSpaces < ActiveRecord::Migration[5.0] 2 def self.up 3 add_column :spaces, :area_id, :integer 4 add_index :spaces, :area_id 5 end 6 7 def self.down 8 remove_index :spaces, :column => :area_id 9 remove_column :spaces, :area_id 10 end 11end 12
※ 2017****_add_area_id_to_restaurants.html.erb
Ruby
1class Area < ApplicationRecord 2 has_many :restaurants 3end
※ are.rb
Ruby
1class Restaurant < ApplicationRecord 2 belongs_to :area 3end
routes.rbを設定しなければならないのですが、ここをどう記載するべきかわからずじまいまです。。
よろしくお願いします><
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2017/05/03 06:48