概要
provideヘルパーでlayoutにパラメータを引き渡す
内容
layoutに動的にパラメータを引渡したいような場合に
provideヘルパーを利用します。
呼び元
- yield(:key)
呼び先
- provide(:key, value)
サンプル
view/layouts/application.html.haml
!!! %html %head %title Rails4demo = stylesheet_link_tag "application", media: "all", "data-turbolinks-track" => true = javascript_include_tag "application", "data-turbolinks-track" => true = csrf_meta_tags %body - if yield(:title) %h1 =yield(:title) - if current_user login user : = current_user.name %hr/ =render :partial => "application/menu" =render :partial => "application/message" = yield
view/application/_menu.html.haml
-if @menu_display = link_to '新規登録', :controller => 'user', :action => 'new' = link_to 'サインアウト', :controller => 'signin', :action => 'signout'
view/application/_message.html.haml
-if @message_display - unless flash[:message].blank? %div %p =flash[:message] %hr/
/view/signin/index.html.haml
- provide(:title, "BookShelfSystem") =form_tag("/signin/signin") do %p =label_tag 'login', 'login' =text_field_tag 'login' %p =label_tag 'password', 'Password' =password_field_tag 'password' %p =submit_tag 'submit'