Mysql 在rails上计算,将答案保存到不同的表中

Mysql 在rails上计算,将答案保存到不同的表中,mysql,ruby-on-rails,ruby,database,ruby-on-rails-4,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

我想在我的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
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
class PlayersController
statplayers_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
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
class StatplayersController

对不起,伙计们,我不知道如何详细说明我的问题。。希望你明白我的意思。。谢谢大家!

你能解释一下你想在哪个表格中保存什么样的公式和数据吗?任何公式。。示例添加。所有输入的数据将保存在玩家表中,然后所有答案将保存在statplayers表中。您如何输入数据?你提交表格了吗?或者访问链接?这些数据包含什么?什么是“答案”?可能输入的数据都是整数。它们将通过表格提交。答案也是整数。