我在rails中使用性感验证来验证我的字段。在使用新操作时,验证如何工作正常但在使用更新操作更新相同时无法正常工作。在更新时我得到模板缺失错误。 控制器
class Admin::AccruedFundsController < ApplicationController
layout 'admin-layout'
before_action :authenticate_user!
#load_and_authorize_resource
def funds_params
params.require(:accrued_fund).permit(:id, :society_id, :satutory_reserve_fund, :building_fund, :depreciation_fund, :all_other_fund)
end
def index
respond_to do |format|
format.html
format.json { render json: AccruedFundsDatatable.new(view_context,current_user) }
end
end
def show
@funds = AccruedFund.find(params[:id])
end
def new
@funds = AccruedFund.new
end
def create
@funds = AccruedFund.new(funds_params)
if @funds.save
flash[:success] = "Successfully Created!"
redirect_to :action => 'index'
else
flash[:error] = "Sorry! Could not complete the request, please try again!"
render :action => "new"
end
end
def edit
@funds = AccruedFund.find(params[:id])
end
def update
@funds = AccruedFund.find(params[:id])
if @funds.update_attributes(funds_params)
flash[:success] = "Successfully Updated!"
redirect_to :action => 'index'
else
flash[:error] = "Sorry! Could not complete the request, please try again!"
render :action => 'update'
end
end
def destroy
if AccruedFund.find(params[:id]).destroy
redirect_to :action => 'index'
flash[:success] = "Successfully Deleted!"
else
flash[:error] = "Sorry! Could not complete the request, please try again!"
redirect_to :action => 'index'
end
end
end
模型中使用的性感验证如下:
class AccruedFund < ActiveRecord::Base
belongs_to :society
validates :society, :presence => true,
:associated => true
validates :satutory_reserve_fund, :presence => true,
:numericality =>true
validates :building_fund, :presence => true,
:numericality => true
validates :depreciation_fund, :presence => true,
:numericality => true
validates :all_other_fund, :presence => true,
:numericality => true
end
答案 0 :(得分:1)
更新操作render :action => 'update'
没有模板。
您应该呈现edit
行动。
注意:
- render :new
也可以正常工作
- 当您使用render
methond时,您必须使用flash.now[:error]
(或注意或成功)。否则,将在下一页触发闪光。