7
5

More than 5 years have passed since last update.

Cellsで定義したViewの内部でhelperメソッドを使う方法

Last updated at Posted at 2013-02-01

以下の2つの比較的メジャーなgemを合わせて利用している時の話。
- cells
- devise

例えばユーザプロフィール用の表示をCellsで定義して、ログインしている、していないで表示を分けたい場合など。DeviseのメソッドをCellsのviewで使いたい場合がある。利用するためにはCellsの「hoge_cell.rb」内で下記の様に記述すれば良い

user_signed_in?メソッドを使う場合
class HogeCell < Cell::Rails
  include Devise::Controllers::Helpers
  helper_method :user_signed_in?

  
end

同じくApplicationHelperに定義しているメソッドを使いたい場合

class HogeCell < Cell::Rails
  helper ApplicationHelper

  ...
end
7
5
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
7
5