我有一个奇怪的问题,我的闪光灯[:notice]正在显示一个额外/随机字符("0").我无法弄清楚它来自哪里.
控制器:
def edit
@subject = Subject.find_by(id: params[:id])
end
def update
@subject = Subject.find_by(id: params[:id])
if @subject.update_attributes(strong_params)
flash[:notice] = 'Subject has been updated'
redirect_to action: 'show', id: @subject.id
else
render 'edit'
end
end
def delete
@subject = Subject.find_by(id: params[:id])
end
private
def strong_params
params.require(:subject).permit(:name, :position, :visible)
end
Run Code Online (Sandbox Code Playgroud)
视图:
= if !flash[:notice].blank?
.notice
= flash[:notice]
%h2 Update subject
= form_for :subject, :url => {action: 'update', id: @subject.id} do |f|
= f.label :name, 'Name:'
= f.text_field :name
= f.label :position, 'Position:'
= …Run Code Online (Sandbox Code Playgroud)