Flash Messages in Partials (Rails 3)

后端 未结 4 739
孤街浪徒
孤街浪徒 2020-12-28 15:13

I have a partial, _flash.html.haml

- flash.each do |type, value|
  .flash{ :class => type.to_s }
    = value 

Which I\'m re

4条回答
  •  渐次进展
    2020-12-28 15:27

    In previous versions of Rails (Rails 2), the default local variable would look for an instance variable with the same name as the partial in the parent.

    Given your example since the partial is named _flash it would automatically pass the instance variable flash as a local to the partial. Thus you would have access to it. This behavior was deprecated in 2.3 and has been removed in Rails 3.0.

    This means that you always have to explicitly pass all instance variables as locals, even flash, just as you wrote in your latter example.

    <%= render :partial => "flash", :locals => {:flash => flash} %>

    This has nothing to do with flash per say, flash is a instance variable just as any other.

提交回复
热议问题