码迷,mamicode.com
首页 > 其他好文 > 详细

rails 增删改查

时间:2018-09-29 23:52:58      阅读:198      评论:0      收藏:0      [点我收藏+]

标签:edit   cti   rails   perm   control   esc   font   str   upd   

class InvoicesController < ApplicationController

  def index
    @invoices = Invoice.all
  end

  def show
    @invoice = Invoice.find(params[:id])
  end

  def new
    @invoice = Invoice.new
  end

  def edit
    @invoice = Invoice.find(params[:id])
  end

  def update
    @invoice = Invoice.find(params[:id])
    if @invoice.update(invoice_params)
      redirect_to invoice_path(@invoice) 
    else
      render :edit
    end
  end

  def create
    @invoice = Invoice.new(invoice_params)
    if @invoice.save
      redirect_to @invoice
    else
      render :new
    end
  end

  def destroy
    @invoice = Invoice.find(params[:id])
    @invoice.destroy
    redirect_to :action => :index
  end

  private

    def invoice_params
      params.require(:invoice).permit(:standard, :unit, :amount, :tax_unit_price, :tax_total, :cess, :tax_money)
    end
end

 

rails 增删改查

标签:edit   cti   rails   perm   control   esc   font   str   upd   

原文地址:https://www.cnblogs.com/znsongshu/p/9726959.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!