ruby on rails - How can you (and should you) access flash, session, and controller instance variables from a view? -
i should start of saying started helpful messages 1 when set devise (as of v. 2.2.3):
ensure have flash messages in app/views/layouts/application.html.erb example: <p class="notice"><%= notice %></p> <p class="alert"><%= alert %></p>
there @ to the lowest degree 3 ways can info view controller. can set things in session, set in flash, or set instance variable in controller. see examples both flash , session accessed bare variable in view, opens possibility of collision. example, have controller this:
class perversecontroller < applicationcontroller def index @msg = 'message 1' session[:msg] = 'message 2' # note - real concern comes in, previous page # have done anything! though here utilize flash.now illustrate point. flash.now[:msg] = 'message 3' end
then, if had next in view:
<%= msg %>
it seem of 3 values might referenced. in fact, code above in view error me (on rails 3.2). need utilize '@' or 'flash' or 'session' explicitly.
i can't find clear documentation on - books , tutorials reference flash , session afterthought, imagine might alter in future versions. but, i'd love see pointer references, , suggestion of should avoid breakage in future while keeping code clear / concise possible.
and now, want create sure integrate devise.
ruby-on-rails ruby-on-rails-3
No comments:
Post a Comment