<file_sep>class MarketReviewsController < ApplicationController
  before_action :set_market_review, only: [:show, :edit, :update, :destroy]

  # GET /market_reviews
  # GET /market_reviews.json
  def index
    @market_reviews = MarketReview.all
  end

  # GET /market_reviews/1
  # GET /market_reviews/1.json
  def show
  end

  # GET /market_reviews/new
  def new
    @market_review = MarketReview.new(market_id: params[:market_id])
  end

  # GET /market_reviews/1/edit
  def edit
  end

  # POST /market_reviews
  # POST /market_reviews.json
  def create
    @market_review = MarketReview.new(market_review_params)

    respond_to do |format|
      if @market_review.save
        format.html { redirect_to @market_review, notice: 'Market review was successfully created.' }
        format.json { render :show, status: :created, location: @market_review }
      else
        format.html { render :new }
        format.json { render json: @market_review.errors, status: :unprocessable_entity }
      end
    end
  end

  # PATCH/PUT /market_reviews/1
  # PATCH/PUT /market_reviews/1.json
  def update
    respond_to do |format|
      if @market_review.update(market_review_params)
        format.html { redirect_to @market_review, notice: 'Market review was successfully updated.' }
        format.json { render :show, status: :ok, location: @market_review }
      else
        format.html { render :edit }
        format.json { render json: @market_review.errors, status: :unprocessable_entity }
      end
    end
  end

  # DELETE /market_reviews/1
  # DELETE /market_reviews/1.json
  def destroy
    @market_review.destroy
    respond_to do |format|
      format.html { redirect_to market_reviews_url, notice: 'Market review was successfully destroyed.' }
      format.json { head :no_content }
    end
  end

  private
    # Use callbacks to share common setup or constraints between actions.
    def set_market_review
      @market_review = MarketReview.find(params[:id])
    end

    # Never trust parameters from the scary internet, only allow the white list through.
    def market_review_params
      params.require(:market_review).permit(:title, :content, :rate, :date, :user_id, :market_id, :image)
    end
end
<file_sep>json.array! @shop_reviews, partial: 'shop_reviews/shop_review', as: :shop_review
<file_sep>class CreateMarkets < ActiveRecord::Migration[5.0]
  def change
    create_table :markets do |t|
      t.string :name
      t.string :address
      t.string :open
      t.boolean :parking
      t.string :tel
      t.string :closed
      t.string :locate1
      t.string :locate2
      t.string :locate3
      t.string :image

      t.timestamps
    end
  end
end
<file_sep># README

This README would normally document whatever steps are necessary to get the
application up and running.

Things you may want to cover:

* Ruby version

* System dependencies

* Configuration

* Database creation

* Database initialization

* How to run the test suite

* Services (job queues, cache servers, search engines, etc.)

* Deployment instructions

* ...

------------------------------------------------

* rails version : 5.0.6(5.0.7)

* Market scaffold
  model로 만든 것 : 가게이름(name) 위치(address) 영업시간(open) 주차가능여부(parking-boolean) 전화번호(tel) 휴일(closed) 시/도(locate1) 군/구(locate2) 동/읍/면(locate3) => parking 빼고 전부 string
  => locate3는 잘못 만든 것 ㅠㅠ

* MarketReview scaffold
  Market(상위) - MarketReview(하위)
  User(상위) - MarketReview(하위)
  model로 만든 것 : 제목(title-string) 내용(content-text) 별점(rate-float) 날짜(date-date)

* Shop scaffold
  Market(상위) - Shop(하위) => 소속
  model로 만든 것 : 가게이름(name) 영업시간(open) 전화번호(tel)

* ShopReview scaffold
  Shop(상위) - ShopReview(하위)
  User(상위) - ShopReview(하위)
  model로 만든 것 : 제목(title-string) 내용(content-text) 별점(rate-float) 날짜(date-date)

* Menu scaffold
  Shop(상위) - Menu(하위)
  model로 만든 것 : 메뉴이름(name) 가격(price-integer) 부가설명(content-text)

* devise gem 사용을 위한 세팅 완료(2018-08-15)

* devise를 이용하여 User, Admin 모델 생성

* admin gem 설치 완료(2018-08-15), 추후에 https://say8425.github.io/setup-rails-admin-1/ 를 참고하여 설정하기
<file_sep>json.extract! market_review, :id, :title, :content, :rate, :date, :created_at, :updated_at
json.url market_review_url(market_review, format: :json)
<file_sep>class ShopReviewsController < ApplicationController
  before_action :set_shop_review, only: [:show, :edit, :update, :destroy]

  # GET /shop_reviews
  # GET /shop_reviews.json
  def index
    @shop_reviews = ShopReview.all
  end

  # GET /shop_reviews/1
  # GET /shop_reviews/1.json
  def show
  end

  # GET /shop_reviews/new
  def new
    @shop_review = ShopReview.new(shop_id: params[:shop_id])
  end

  # GET /shop_reviews/1/edit
  def edit
  end

  # POST /shop_reviews
  # POST /shop_reviews.json
  def create
    @shop_review = ShopReview.new(shop_review_params)

    respond_to do |format|
      if @shop_review.save
        format.html { redirect_to @shop_review, notice: '가게 리뷰 작성 완료' }
        format.json { render :show, status: :created, location: @shop_review }
      else
        format.html { render :new }
        format.json { render json: @shop_review.errors, status: :unprocessable_entity }
      end
    end
  end

  # PATCH/PUT /shop_reviews/1
  # PATCH/PUT /shop_reviews/1.json
  def update
    respond_to do |format|
      if @shop_review.update(shop_review_params)
        format.html { redirect_to @shop_review, notice: '가게 리뷰 수정 완료' }
        format.json { render :show, status: :ok, location: @shop_review }
      else
        format.html { render :edit }
        format.json { render json: @shop_review.errors, status: :unprocessable_entity }
      end
    end
  end

  # DELETE /shop_reviews/1
  # DELETE /shop_reviews/1.json
  def destroy
    @shop_review.destroy
    respond_to do |format|
      format.html { redirect_to shop_reviews_url, notice: '가게 리뷰가 삭제되었습니다.' }
      format.json { head :no_content }
    end
  end

  private
    # Use callbacks to share common setup or constraints between actions.
    def set_shop_review
      @shop_review = ShopReview.find(params[:id])
    end

    # Never trust parameters from the scary internet, only allow the white list through.
    def shop_review_params
      params.require(:shop_review).permit(:title, :content, :rate, :date, :user_id, :shop_id, :image)
    end
end
<file_sep>json.partial! "shop_reviews/shop_review", shop_review: @shop_review
<file_sep>json.partial! "market_reviews/market_review", market_review: @market_review
<file_sep>json.extract! shop, :id, :name, :open, :tel, :created_at, :updated_at
json.url shop_url(shop, format: :json)
<file_sep>class Shop < ApplicationRecord
  mount_uploader :image, ImageUploader
  belongs_to :market
  has_many :menus
  has_many :shop_reviews
end
<file_sep>json.array! @market_reviews, partial: 'market_reviews/market_review', as: :market_review
<file_sep>class Market < ApplicationRecord
  mount_uploader :image, ImageUploader
  has_many :shops
  has_many :market_reviews
end
<file_sep>class ShopReview < ApplicationRecord
  mount_uploader :image, ImageUploader
  belongs_to :shop
  belongs_to :user

  validates :user, presence: true
end
<file_sep>json.extract! shop_review, :id, :title, :content, :rate, :date, :created_at, :updated_at
json.url shop_review_url(shop_review, format: :json)
<file_sep>Rails.application.routes.draw do
  devise_for :users
  resources :shop_reviews
  resources :market_reviews
  resources :menus
  resources :shops
  resources :markets
  # For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html

  root 'markets#index'
end
<file_sep>class MarketReview < ApplicationRecord
  mount_uploader :image, ImageUploader
  belongs_to :market
  belongs_to :user

  validates :user, presence: true
end
<file_sep>json.extract! market, :id, :name, :address, :open, :parking, :tel, :closed, :locate1, :locate2, :locate3, :image :created_at, :updated_at
json.url market_url(market, format: :json)
