如何根据其投标创建预订?

时间:2016-01-28 14:58:47

标签: ruby-on-rails ruby ruby-on-rails-3 ruby-on-rails-4

我有一个模型音调,我正在获取grounddetail_id。我想展示地面上可用的所有音高。我怎么能预定地面的间距..

grounddetails_controller.rb

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

的routes.rb

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

现在我只有音高模型和路线,但在控制器中我很困惑使用什么。我可以预订地面的间距。但是对于单一的基础,我能够预订。

1 个答案:

答案 0 :(得分:0)

grounddetails#show行动中

def show
  @pitches = @grounddetail.pitches
end

然后在groundetails/show.html.erb中,您只需使用<%= @pitches %>即可显示pitches的{​​{1}}。

<强> 更新

grounddetail