flash [:notice]显示额外的字符

时间:2014-04-17 21:34:44

标签: ruby-on-rails ruby 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

查看:

   = 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

1 个答案:

答案 0 :(得分:5)

所以,事实证明答案是:将'大声'haml = if !flash[:notice].blank?改为'沉默'- if !flash[:notice].blank?