在轨道上计算,保存不同表格的答案

时间:2015-01-20 01:54:48

标签: mysql ruby-on-rails ruby database ruby-on-rails-4

我想在我的rails项目上添加一些公式。问题是我不知道如何在不同的表格中保存答案。顺便说一句,所有输入的数据也意味着保存。

这些是我的代码

players_controller.rb

class PlayersController < ApplicationController
  before_action :set_player, only: [:show, :edit, :update, :destroy]

  # GET /players
  # GET /players.json
  def index
    @players = Player.all
  end

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

  # GET /players/new
  def new
    @player = Player.new
  end

  # GET /players/1/edit
  def edit
  end

  # POST /players
  # POST /players.json
  def create
    @player = Player.new(player_params)

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

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

  # DELETE /players/1
  # DELETE /players/1.json
  def destroy
    @player.destroy
    respond_to do |format|
      format.html { redirect_to players_url, notice: 'Player was successfully destroyed.' }
      format.json { head :no_content }
    end
  end

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

    # Never trust parameters from the scary internet, only allow the white list through.
    def player_params
      params.require(:player).permit(:playernum, :playername, :team, :fgm2, :attmpt, :fgm3, :attmpt2, :ftm, :attmpt3, :off, :def, :tot, :ast, :to, :pf, :stl, :blk, :pts, :gp, :opp, :game, :venue, :date)
    end
end

statplayers_controller.rb

class StatplayersController < ApplicationController
  before_action :set_statplayer, only: [:show, :edit, :update, :destroy]

  # GET /statplayers
  # GET /statplayers.json
  def index
    @statplayers = Statplayer.all
  end

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

  # GET /statplayers/new
  def new
    @statplayer = Statplayer.new
  end

  # GET /statplayers/1/edit
  def edit
  end

  # POST /statplayers
  # POST /statplayers.json
  def create
    @statplayer = Statplayer.new(statplayer_params)

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

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

  # DELETE /statplayers/1
  # DELETE /statplayers/1.json
  def destroy
    @statplayer.destroy
    respond_to do |format|
      format.html { redirect_to statplayers_url, notice: 'Statplayer was successfully destroyed.' }
      format.json { head :no_content }
    end
  end

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

    # Never trust parameters from the scary internet, only allow the white list through.
    def statplayer_params
      params.require(:statplayer).permit(:gpyd, :apts, :adef, :areb, :aast, :astl, :ablk, :a2fga, :a2fgm, :a3fga, :afta, :aftm, :ato, :apf)
    end
end
抱歉,伙计们,我不知道如何详细阐述我的问题。希望你明白我的意思..谢谢你!

0 个答案:

没有答案