use*_*328 1 ruby ruby-on-rails ruby-on-rails-4
我有一个奇怪的问题,我的闪光灯[: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:'
= f.text_field :position
= f.label :visible, 'Visible:'
= f.text_field :visible
= f.submit 'Update Subject'
%h2
Are you sure you want to delete the subject - #{@subject.name}
= link_to 'Yes, delete!', action: 'destroy', id: @subject.id
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
62 次 |
| 最近记录: |