Skip to content

Instantly share code, notes, and snippets.

@tkawa
Created March 26, 2014 11:12
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tkawa/9781005 to your computer and use it in GitHub Desktop.
Save tkawa/9781005 to your computer and use it in GitHub Desktop.
Railsのビューヘルパー内でHamlを使う
module ApplicationHelper
def render_thumbsup_button(options)
options[:url] ||= thumbsup_path
options[:method] ||= :put
options[:count] ||= 0
# ローカル変数を渡したいときのみ locals が必要
render inline: <<-HAML.strip_heredoc, type: :haml, locals: options
.thumbsup
= form_tag url, method: method do
%button.btn.btn-xs
= t('label.thumbsup')
- if count > 0
.span.badge
%span.glyphicon.glyphicon-thumbs-up
%span= count
HAML
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment