我有一个模型音调,我正在获取grounddetail_id。我想展示地面上可用的所有音高。我怎么能预定地面的间距..
class GrounddetailsController < ApplicationController
before_action :find_ground, only: [:show, :edit, :destroy, :update]
def index
@grounddetails = Grounddetail.all.order('created_at DESC')
end
def new
@grounddetail = Grounddetail.new
end
def edit
end
def show
end
def create
@grounddetail = Grounddetail.new(ground_params)
if @grounddetail.save
redirect_to @grounddetail
else
render 'new'
end
end
def update
if @grounddetail.update(ground_params)
redirect_to @grounddetail
else
render 'edit'
end
end
def destroy
@grounddetail.destroy
redirect_to root_path
end
private
def find_ground
@grounddetail = Grounddetail.find(params[:id])
end
def ground_params
params.require(:grounddetail).permit(:name, :working_hours, :end_time, :address, :contact_no, :email, :number_of_grounds, :description, :featured_ground)
end
end
Rails.application.routes.draw do
devise_for :users
devise_for :admins
resources :grounddetails do
resources :pitches
end
root "grounddetails#index"
end
grounddetail.rb
class Grounddetail < ActiveRecord::Base
has_many :pitches, dependent: :destroy
end
pitch.rb
class Pitch < ActiveRecord::Base
belongs_to :grounddetail
end
现在我只有音高模型和路线,但在控制器中我很困惑使用什么。我可以预订地面的间距。但是对于单一的基础,我能够预订。
答案 0 :(得分:0)
在grounddetails#show
行动中
def show
@pitches = @grounddetail.pitches
end
然后在groundetails/show.html.erb
中,您只需使用<%= @pitches %>
即可显示pitches
的{{1}}。
<强> 更新 强>
grounddetail